0
Python code not working
Hi am an ameture who is learning python and i wrote this code in python which calculates THE CODE: print("Integer1:") a = input() print("Integer2:") b = input() print("If add type:1") print("If subtract type:2") print("If multiply type:3") print("If divide type:4") c = input("") if c=="1": print(a+b) if c=="2": print(a-b) if c=="3": print(a*b) if c=="4": print(a/b) Please help me out guys
2 Answers
+ 4
input() return a string type object.
0
Siva Sai Devesh,
I think you are creating a calculator so for that, you can do this too:
here is a code by ă
€ă
€ă
€ :
x=int(input("enter first no.: "))
y=input('enter the arithematic operation (+,-,*,/): ')
z=int(input('enter second no.: '))
if y=='-':
print(x-z)
elif y=='+':
print(x+z)
elif y=='*':
print(x*z)
elif y=='/':
print(x/z)
don't use the user prompt if you are using it in sololearn (cuz its of no use).
you can take input as floats if you want (just change `int to float`)
Credit: @~NEZ