0
How to solve indentation error in python? Please help me.
5 ответов
+ 2
Post the code here.
+ 2
# Corrected Version
while True:
print(" Options ")
print("enter 'add' to add two numbers")
print("enter 'sub' to add two numbers")
print("enter 'multiply' to add two numbers")
print("enter 'division' to add two numbers")
print("enter 'module' to get reminder of two numbers")
print("enter 'quit' to quit the program")
user_input=input()
if user_input=="quit":
break
elif user_input=="add":
# add some code
elif user_input=="sub":
# add some code
elif user_input=="muliply":
# add some code
elif user_input=="division":
# add some code
elif user_input=="module":
# add some code
else:
print(unknown input")
+ 1
i hope you are talking about your calculator program
So, here indentation means spacing
Unlike c++, in python white space matters
mistakes in your program
you wrote the statements in while loop without giving space in the beginning(indentation).
correct form would be:
while true:
print( "Options" )
print("enter 'add' to add two numbers")
^ see the tab, it matters and it should be consistent for all other print statement in the " while loop ". same is applicable for if statement
+ 1
oky thanks sreejith
0
while true:
print(" Options ")
print("enter 'add' to add two numbers")
print("enter 'sub' to add two numbers")
print("enter 'multiply' to add two numbers")
print("enter 'division' to add two numbers")
print("enter 'module' to get reminder of two numbers")
print("enter 'quit' to quit the program")
user_input=input(:)
if user_input=="quit":
break
elif user_input=="add":
elif user_input=="sub":
elif user_input=="muliply":
elif user_input=="division":
elif user_input=="module":
elif print(unknown input")