+ 1

# I tried to make a calculator, it DOES WORK NOW! :D

x=input('Enter a number?\n') y=input("Enter another one!\n") z=input('1 to + \n 2 to - \n 3 to * \n 4 to /\n') if z=='1': print(int(x)+int(y)) if z=='2': print(int(x)-int(y)) if z=='3': print(int(x)*int(y)) if z=='4': print(int(x)/int(y)) IT WORKED :D

6 Answers

+ 1

Your variables are strings right now...
try
if z='1'
print (int(x)+int(y))
then go through it with choosing 2 numbers and make sure you use 1 operator...it'll work.
That should point you in the right direction.

0

print (int(x)+int(y)) what is the diffrence?

0

x=input('Enter a number?\n')
y=input("Enter another one!\n")
z=input('1 to + \n 2 to - \n 3 to * \n 4 to /\n')
if z==1:
print(int(x)+int(y))
if z==2:
print(int(x)-int(y))
if z==3:
print(int(x)*int(y))
if z==4:
print(int(x)/int(y))
is the new code, it's still blank

0

int(x) converts your x variable from a string to an integer.
The best way to resolve your issue right now...would be to convert all of your inputs to an integer at the time of entry.
i.e.
x=int(input())
If you do that with each of your 3 variables, then the rest of your code should work.

0

The trouble with this code, is that your z variable is still a string
when you are comparing it, you are comparing it to an Integer (whole number)
if you do this if z=='1' then you are saying:
If z is equal to the string 1 (the quotes make it a string)
x=input('Enter a number?\n')
y=input("Enter another one!\n")
z=input('1 to + \n 2 to - \n 3 to * \n 4 to /\n')
if z==1:
print(int(x)+int(y))
if z==2:
print(int(x)-int(y))
if z==3:
print(int(x)*int(y))
if z==4:
print(int(x)/int(y))
is the new code, it's still blank

0

The new code works.
I also put '' around the numbers like
if z=='2':