Ask coding questions

← Back to all posts
Error message makes no sense
SolomonKnutzen1 (5)

Whenever I try and run the program, it gives me this error message: File "main.py", line 28 elif main == 'No': IndentionError: expected an indented block. This makes no sense to me so if you could help it would be welcome.

Commentshotnewtop
CodingCactus (3039)

you never put anything under the else: on line 27

After an else: it expects there to be some indented code, but there isn't so there is an error.

JosephSanthosh (1192)

As a matter of fact, he doesn't even need an else statement so it's better if it's deleted! @CodingCactus

maxyang (77)

Either delete the else or put a pass after it.

JosephSanthosh (1192)

Sorry here is the correct code for your program:

quit = False
import time
elements = {
'H' : 1.0079, 'He' : 4.0026, 'Li'  : 6.941, 'Be' : 9.0122,'B' : 10.811,'C' : 12.011, 'N' : 14.0067, 'O' : 15.9994,'F' : 18.9984,'Ne' : 20.1797, 'Na' : 22.9898, 'Mg' : 24.3050, 'Al' : 26.9815, 'Si' : 28.085, 'P' : 30.9738, 'S' : 32.065, 'Cl' : 35.45, 'Ar' : 39.948, 'K' : 39.0983, 'Ca' : 40.078, 'Sc' : 44.9559,'Ti' : 47.867, 'V' : 50.9415, 'Cr' : 51.9961, 'Mn' : 54.9380, 'Fe' : 55.845, 'Co' : 58.9332, 'Ni' : 58.6934, 'Cu' : 63.546, 'Zn' : 65.409, 'Ga' : 69.723, 'Ge' : 72.64, 'As' : 74.9216, 'Se' : 78.96, 'Br' : 79.904, 'Kr' : 83.798, 'Rb' : 85.4678, 'Sr' : 87.62, 'Y' : 88.9059, 'Zr' : 91.224, 'Nb' : 92.9064, 'Mo' : 95.94, 'Tc' : 97.9072, 'Ru' : 101.07, 'Rh' : 102.9055, 'Pd' : 106.42, 'Ag' : 107.8662, 'Cd' : 112.411, 'In' : 114.818, 'Sn' : 118.710, 'Sb' : 121.760, 'Te' : 127.60, 'I' : 126.9045, 'Xe' : 131.293, 'Cs' : 132.9055, 'Ba' : 137.237, 'La' : 138.9055, 'Hf' : 178.49, 'Ta' : 180.9479, 'W ' : 183.84, 'Re' : 186.207, 'Os' : 190.23, 'Ir' : 192.217, 'Pt' : 195.078, 'Au' : 196.9666, 'Hg' : 200.59, 'Ti' : 204.3833, 'Pb' : 207.2, 'Bi' : 208.9804, 'Po' : 208.9824, 'At' : 209.987, 'Rn' : 22.0176, 'Fr' : 223.0197, 'Ra' : 226.0254, 'Ac' : 227.0277, 'Rf' : 261.1088, 'Db' : 262.1141, 'Sg' : 266.1219, 'Bh' : 264.12, 'Hs' : 277, 'Mt' : 268.1388, 'Ds' : 247.0704, 'Rg' : 280, 'Cn' : 285, 'Nh' : 284, 'Fl' : 289, 'Mc' : 288, 'Lv' : 293, 'Ts' : 294, 'Og' : 294, 'Ce' : 140.116, 'Pr' : 140.9077, 'Nd' : 144.24, 'Pm' : 144.9124, 'Sm' : 150.36, 'Eu' : 151.964, 'Gd' : 157.25, 'Tb' : 158.9253, 'Dy' : 162.50, 'Ho' : 164.9303, 'Er' : 167.259, 'Tm' : 168.9342, 'Yb' : 173.04, 'Lu' : 174.967, 'Th' : 232.0381, 'Pa' : 231.0359, 'U' : 238.0289, 'Np' : 237.0482, 'Pu' : 244.0642, 'Am' : 243.0614, 'Cm' : 247.0704, 'Bk' : 247.0703, 'Cf' : 251.0796, 'Es' : 252.0830, 'Fm' : 257.0951, 'Md' : 258.0984, 'No' : 259.101, 'Lr' : 262.1097
}
#program
print ('Do you need a Stoich calculation done? Yes or No')
main = input('')
if main == 'Yes':
  print ('What is your starting element?')
  starting_element_one = input()
  print ('How many of the starting element are there?')
  starting_element_count_one = int(input())
  starting_element_one_num = elements.get(starting_element_one)
  starting_element_amount_one = starting_element_one_num * starting_element_count_one
  print (starting_element_amount_one, 'of', starting_element_one)
  print ('Are there more than 2 elements?')
  two = input('')
  if two == 'Yes':
    print ('What is your second element?')
    second_element_two = input()
    print ('How many of the second element are there?')
    second_element_count_two = int(input())
    second_element_two_num = elements.get(second_element_two)
    second_element_amount_two = second_element_two_num * second_element_count_two
    print (second_element_amount_two, 'of', second_element_two)
  else:
    pass
elif main == 'No':
  print('Good Bye')
  time.sleep(1)
  quit = True

Hope this helped and have a great day coding :)

JosephSanthosh (1192)

Ban? He's probably your fan or something... @ZDev1

ZDev1 (654)

@JosephSanthosh no he's not
look at my projects
they are not so good to get a fan

JosephSanthosh (1192)

ohhh, well at least you're better than me. @ZDev1

JosephSanthosh (1192)

Aha! You have an interesting mistake here! In python you cannot have an else statement with nothing inside or under it! So just go to line 34 and delete the else statement! That's it! Here is the fixed version of your code, just fork it: https://repl.it/@JosephSanthosh/Stoich-Calcuator

Hope this helped and have a great day !

ImmaEatYouMan (17)

first of all, put elif before else. second never put anything under else on line 33. third, you see that line that stretches down from if? Well for elif to be included in the if statement the elif needs to be ON THAT LINE.It should look like this
PLEASE MARK AS ANSWERED IF THIS HELPED

svcbnmc (0)

Try adding a Collin

TinaChen4 (13)

@JosephSanthosh this : But it won't help. You need code under the else or just delete it

JosephSanthosh (1192)

You won't help? I'm a little confused over what you are saying. @TinaChen4

TinaChen4 (13)

@JosephSanthosh Oops, spelling error its supposed to be it won't help. The colon(:)

JosephSanthosh (1192)

yea a colon won't help, you're right, it's much easier to just delete it, honestly. @TinaChen4

TinaChen4 (13)

@JosephSanthosh ye. But he fixed it. and more errors appear

DungeonMaster00 (131)

python ignores blank lines even if it is not indented btw

k9chelsea2 (650)

an indent is a whitespace or a tab btw

Lethdev2019 (183)

@SolomonKnutzen1

The reason this is occurring is that on line 34 - it expects and indented block (with a command) because of the else statement on line 33. So you must add pass or something like print or delete it to get rid of the error.

note that else: should under no circumstances be left empty - either add pass or continue or just remove else.

AmazingMech2418 (910)

When it says SyntaxError: unexpected EOF while parsing, EOF means "End Of File". Basically, since you have no code in the else statement, it expects something to be there and since there is nothing, it throws the error because the end of the file came unexpectedly. Try adding pass to the else statement and it should work! I see you already fixed the original error though.

JosephSanthosh (1192)

As a matter of fact, he doesn't even need an else statement so it's better if it's deleted! @AmazingMech2418

PattanAhmed (1103)

@SolomonKnutzen1 Hi,
It's just a silly error!
In your code, it's in line 27.
It's because you just left that else statement without anything inside.
If you want your code to continue, then add a pass statement under that else function.
And the second thing is:-
That there was no indent under the else statement.

Your code should look like this after all:-

  else:
    pass

On line 27.
That's it
Thanks!

Hope this helps

DungeonMaster00 (131)

@PattanAhmed you didn't say anything about indentation though

PattanAhmed (1103)

@nk1rwc He has correct indentation.
Just under his else command nothing was available and Python was thinking that why is this thing empty.

LoL!

DungeonMaster00 (131)

@PattanAhmed yeah try to make you're answers helpful and tell them what's wrong.

DungeonMaster00 (131)

@PattanAhmed tell them that there was no indent under the else

JosephSanthosh (1192)

As a matter of fact, he doesn't even need an else statement so it's better if it's deleted! @PattanAhmed

PattanAhmed (1103)

@JosephSanthosh Yes, it's better...
But for his sake, Let him keep it.

PattanAhmed (1103)

@SolomonKnutzen1 Welcome!
Happy to help you.

Please mark my answer if that helps!
Thanks!

DungeonMaster00 (131)

The problem here is that the else is not indented.

Indentation is how Python keeps track of the ifs, elifs, and elses, and any other blocks of code.

The problem here is that you did not indent after the else.

So an error occurs if there is no indent.

You un-indent when you want to end the else or any other conditional statement or loop.

Thanks.

DungeonMaster00 (131)

@nk1rwc and its also cool that the program is based on the elements.

JosephSanthosh (1192)

As a matter of fact, he doesn't even need an else statement so it's better if it's deleted! @nk1rwc