[Tutor] Invalid syntax error in my program

Alan Gauld alan.gauld at yahoo.co.uk
Fri Aug 19 13:23:08 EDT 2016


On 19/08/16 15:36, Kalpesh Naik wrote:

> #SIMPLE CALCULATOR

> while True:
>     n=int(input("Enter your choice:"))
>     a=int(input("Enter 1st value:"))
>     print("1st value is:",a)
>     b=int(input("Enter 2nd value:"))
>     print("2nd value is:",b)
>     if n==1:
>         c=a+b
>         print("Addition is : ",c)
>         elif n==2:
>             d=a-b

The elif line should be aligned with the if line like this:


if <condition>:
     XXXXX
     XXXXX
elif <another condition>:
     YYYYY
     YYYYY
elif <and another>:
     ZZZZZ
     ZZZZZ
else:
     AAAAA


The indentation is what python uses to figure out where
the blocks (X,Y and Z) end. Aligned as you have it Python
tries to interpret the elif as if it were part of the
if block.

>                     elif n==5:
>                         z=a%b
>                         print("modules is : ",z)

I think you mean modulo not modules.
Modules, especially in Python, means something very different.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list