beginner's problem

+1 Saša Krnojelac · March 2, 2015
First of all thanks for the tutorials. I do not know much English,but the tutorials are well placed. I began to learn python. I try to make a calculator. I do not know what's wrong. (Syntax eror)

 print ("Welcome to the calculator!!!")
print
x=input("Enter the number: ")
o=input("Enter the operation (+,-,*,/) ")
y=input("Enter the number: ")
if o is + :
    print("You have selected collection")
    r=x+y
    print("Result is: "),r
elif o is -:
    print("You have selected subtraction")
    r=x-y
    print("Result is: "),r
elif o is *:
    print("You have selected multiplication")
    r=x*y
    print("Result is: "),r
elif o is /:
    print("You have selected sharing")
    r=x/y
    print("Result is: "),r
else :
    print("Have not entered the correct operation")


Post a Reply

Replies

Oldest  Newest  Rating
0 bob babuinas · March 2, 2015
Have ia you tried instead if is put == and instead of + put "+"? Since you are working with strings you need to check if string is eaqual to another string. If o=="+": try this if statement 
0 Saša Krnojelac · March 2, 2015
Thank you very much, but now I have another probelm. 

1)When you enter the number and operation program we not collect
2)When pick a seizure or another operation program throws an error 

/images/forum/upload/2015-03-02/43017ae05b380b3717fac369892a80b1.jpg
0 Jinjoo Hat · March 3, 2015
Hello there! Seems like it's still reading it as a string. To convert this to an integer, type in int and enclose it in parenthesis. 


x=int(input("Enter the number: "))

y=int(input("Enter the number: "))



More info here: https://docs.python.org/3.4/library/stdtypes.html
Also, there's another problem with your code. the variable r is outside the print function so the result will not print if you run this. Put r inside the parenthesis like so:

print("Result is: ",r)
0 Saša Krnojelac · March 5, 2015
Thank you very much, but now I have another probelm.

When I start the program it closes after I enter the number 2 !!!
/images/forum/upload/2015-03-05/d067da8cbee4a2236ba5e31290fc9236.jpg
  • 1

Python

107,249 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator