boob00 Posted November 23, 2013 Share Posted November 23, 2013 Hello all, I am new to python and am having trouble with an if elif statement. My code is as follows: num1 = raw_input('Number: '); if num1 > 140: print 'high' elif num1 < 80: print 'low' When i run this, and i put in say 150 it tells me that the number is high as expected, but when i run it and put in say 60, it still days high. Any help is grately appreciated. -Boob00 Quote Link to comment Share on other sites More sharing options...
Sitwon Posted November 24, 2013 Share Posted November 24, 2013 Your syntax looks correct to me. Is that the exact source code that is giving you trouble? three questions: 1) why do you have a semicolon at the end of the first line? 2) why are 'if' and 'elif' indented relative to the first line? 3) have you verified that you're not mixing tabs and spaces for indentation? Quote Link to comment Share on other sites More sharing options...
newbi3 Posted November 24, 2013 Share Posted November 24, 2013 The issue is raw_input() gets a string value which he is comparing with a int value. The solution would be to change raw_input() to input() or convert num1 to an int value with the int() function Quote Link to comment Share on other sites More sharing options...
boob00 Posted November 24, 2013 Author Share Posted November 24, 2013 The issue is raw_input() gets a string value which he is comparing with a int value. The solution would be to change raw_input() to input() or convert num1 to an int value with the int() function Thank you for helping, it works now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.