0

Can anyone tell what is wrong in the following code created by me .

def add(x,y): return (x+y) def subtract(x,y): return (x-y) def multiply(x,y): return (x*y) def divide(x,y): return(x/y) #operations selection from user print ("select operations: ") print("1.add") print("2.subtract") print("3.multiply") print ("4.divide") #user choice choice = input("enter the choice(1/2/3/4): ") if choice in ('1','2','3','4'): number1 = input("enter the number1: ") number2 = input ("enter the number2: ") if choice =='1': print(number1 + number2 ) elif choice == '2': print(number1 - number2 ) elif choice == '3' : print(number1 * number2 ) elif choice == '4': print (number1 / number2 )

2nd Oct 2020, 6:44 PM
Aditya Singh
Aditya Singh - avatar
2 Antworten
+ 3
Take number1 and number2 inputs as integers. Use int constructor to convert input to integer. number1 = int(input(......)) number2 = int(input(......))
2nd Oct 2020, 6:59 PM
XXX
XXX - avatar
+ 2
You can call each function with appropriate choise instead of print statement so why you define them ?You can use switch with case value to deal with user choises.
2nd Oct 2020, 7:36 PM
HBhZ_C
HBhZ_C - avatar