+ 1

Something error in my simple calculator app using Python. Please help me to fix it.

def add(x,y): return x+y def sub(x,y): return x-y print("1=add") print("2=subtract") op=input("") x=input("First Number") y=input("Second number") if op=='1': print(add(x,y)) elif op=='2': print(sub(x,y)) else: print("invalid") Link : https://code.sololearn.com/c39SgSsP92xG/#py

27th Apr 2019, 9:24 AM
Shaheem PP
Shaheem PP - avatar
2 Respuestas
+ 9
`input` function returns a string, you need to convert them into a type that supports arithmetic operations. If you want the numbers as integers (whole number) use int() as follows: x = int(input("First Number")) y = int(input("Second Number")) And if you want the numbers as floating point (fractal number) use float() as follows: x = float(input("First Number")) y = float(input("Second Number")) Hth, cmiiw
27th Apr 2019, 9:42 AM
Ipang