Public Group

# Python Problems

This topic is 4675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

a = input("Give me a number... ")
b = input("And one more number... ")
input("I am now adding those two numbers together...")
If a + b &gt; 100:
print "Wow! Thats above 100!!"
elif a + b &lt; 100:
print "Uh oh! Thats below 100... although it makes no difference!"
elif a + b = 100:
print "Hey! Thats EXACTLY 100!"
else:
print "Hrmmmm... you may want to try that again, it seems we've got a problem!"


I'm learning Python right now, and have reached the if statements, however, when I try to run it, I get a syntax error. When I run it through the given Python Package, it highlights the a in, If a + b > 100: So my guess, is that all the other variables will have problems too, as the given package only highlights one problem at a time. BTW: Im programming this in a text editor, that supports indents and color coding called ConTEXT, but it doesn't have a debugger, are there any good python debuggers out there, so I dont have to port it to the python package thing if I get an error?

##### Share on other sites
That's because Python is case sensitive, and you misspelled if as If.

##### Share on other sites
a = input("Give me a number... ")b = input("And one more number... ")input("I am now adding those two numbers together...")if a + b > 100:   print "Wow! Thats above 100!!"elif a + b < 100:   print "Uh oh! Thats below 100... although it makes no difference!"elif a + b = 100:   print "Hey! Thats EXACTLY 100!"else:   print "Hrmmmm... you may want to try that again, it seems we've got a problem!"

Ok, changed If to if, but it still doesn't work.

##### Share on other sites
elif a + b == 100:

##### Share on other sites
Hey, Thanks!

Also to note, that it wasn't working after the =. == fixed, and so I found out, that I had to do raw_input("........"), if I just wanted a pause, because input gave me a problem when I just hit enter, it wanted a number I guess.

BTW: What exactly, is ==? Whats the difference between using that and just simple =?

##### Share on other sites
The '=' is the assignment operator -- notice that you use it to assign a to the returned value of input(). '==' is the operator to check equivalence, "is equal to".

##### Share on other sites
Also, raw_input gives you a string and you want a number. For inputing numbers you should use a = int(raw_input("Gimme a number: "))

Oxyd

##### Share on other sites
input() give you an int, so it's fine to use that.

##### Share on other sites
Not quite. input() gives you the result of interpreting the input line as a Python expression. As such, you might not want to use it in production code.

Converting the raw_input result to an int will work fine as long as that's what the user put in. Otherwise it will raise ValueError; you may want to trap that.

print "Here is a menu"print "1 - do something!"print "2 - do something else!"while True:  try:    selection = int(raw_input("give me a blasted number!"))    if selection in (1, 2): break # we got what we need  except ValueError: # something that wasn't a number got input    continue # try againprint "You now have %d widgets." % (selection * 42)

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 10
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999987
×