Jump to content

Python elif help


boob00

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...