0
What is defect in this program?
while true : print("options :") Print("enter'add'to add two numbers") Print("enter'subtract'to subtract two numbers") Print("enter'quit'to end the program") users_input= input(":") if user_input= 'add': num1= float(input("entera number")) num2 = float(input("enter another number")) result= str(num1+num2) print("the answer is + result") elif user_input= "subtract": num1= float(input("enter a number")) num2= float(input("enter another number")) result= (num1- num2) print("the answer is + result") elif user_input= 'quit': print ("end the program")
3 Respuestas
+ 5
Looks like you're ignoring indentation completely.
Wrong:
if condition:
do_something()
Correct:
if condition:
do_something()
Also, note that python is case sensitive. It's 'print', not 'Print'.
The comparison operator is ==, not = (if condition == True)
0
thanks
0
Also when you are trying to include a variable into a print statement you need to be careful where the " are and convert your variable type to a string:
print("the answer is " + str(result))