Noob Alert - Simple calculator

This is the place for queries that don't fit in any of the other categories.

Noob Alert - Simple calculator

Postby dantheman » Wed Apr 02, 2014 9:06 pm

I was making a simple addition and subtraction calculator, but I tried to test it in IDLE and apparently the syntax is incorrect. Can anybody tell me whats wrong?

Code: Select all
print "Welcome to my simple calculator. You can either add or subtract 2 numbers."
choice = raw_input("Type add for addition or minus for subtraction.")

if choice = add:
    a = raw_input("Enter your first number")
    b = raw_input("Enter your second number")
    final add = a + b
    print final add
   
elif choice = minus:
    c = raw_input("Enter your first number")
    d = raw_input("Enter your second number")
    final sub = c - d
    print final sub
   
else:
    print "You did not select addition or subtraction"


Thanks in advance for the help
dantheman
 
Posts: 2
Joined: Wed Apr 02, 2014 9:02 pm

Re: Noob Alert - Simple calculator

Postby stranac » Wed Apr 02, 2014 9:17 pm

If you get an error, you should post it.
In this case, the error is obvious, though.

= is the assignment operator, == is the comparison operator.
You should use == in your if statements.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1125
Joined: Thu Feb 07, 2013 3:42 pm

Re: Noob Alert - Simple calculator

Postby dantheman » Wed Apr 02, 2014 9:55 pm

Thanks for the help. The smallest things can make so much difference!
Usually i would post the error, but i could tell it was something really small so i didn't see much point tbh.
thanks again.
dantheman
 
Posts: 2
Joined: Wed Apr 02, 2014 9:02 pm

Re: Noob Alert - Simple calculator

Postby stranac » Wed Apr 02, 2014 10:02 pm

dantheman wrote:Usually i would post the error, but i could tell it was something really small so i didn't see much point tbh.

Posting an error can help locate the problem faster, and it can never be bad, so you should do it, even if you don't think it's necessary.
It saves us the trouble of asking for it when it's really needed.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1125
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: W3C [Linkcheck] and 4 guests