What is defect in this program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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")

27th Oct 2018, 3:12 AM
bhuwan
bhuwan - avatar
3 Answers
+ 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)
27th Oct 2018, 5:10 AM
Anna
Anna - avatar
0
thanks
27th Oct 2018, 5:21 AM
bhuwan
bhuwan - avatar
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))
27th Oct 2018, 6:11 AM
Shane