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!"
Python Problems
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.
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 =?
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 =?
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".
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
Oxyd
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.
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement