Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:55:27+00:00 2026-06-13T05:55:27+00:00

In the below python code var=input(Enter a number between 1 to 10:) if (var==1

  • 0

In the below python code

    var=input("Enter a number between 1 to 10:")
    if (var==1 or var==2 or var==3 or var==4 or var==5):
          print ('the entered number is between 1 to 5')
    elif (var==6 or var==7 or var==8 or var==9 or var==10):
          print ('The entered number is between 5 to 10')
    else:
          print ('Wrong value exiting!!')

When i run it in terminal~$ python name.py

Enter a number between 1 to 10:3

the entered number is between 1 to 5

when i run it in terminal~$ python3 name.py

Enter a number between 1 to 10:3

Wrong value exiting!!

What makes the difference ? & what i have to change in order to get the correct output when i compile with python3`?


is there any simpler way of comparison instead of using “or” for every number ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:55:28+00:00Added an answer on June 13, 2026 at 5:55 am

    In Python 2:

    var=input("Enter a number between 1 to 10:")
    

    The above evaluates the expression, so it ends up with var potentially equalling a number. (And as a note should really be avoided)

    In Python 3, input is the equiv. of raw_input in Python 2, so it returns a string – if you expect it to be a number you need to do var = int( input("...") ) and be aware of any conversion errors that may occur:

    There is the in operator:

    if var in (1, 2, 3, 4, 5):
        pass
    elif var in (6, 7, 8):
        pass
    else:
        pass
    

    Or, if you want a between operation, you can make use of the Python logic system:

    if 1 <= var <= 5:
        pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the code shown below, I need to manipulate the time var in python
How can I implement the below code (ActionScript) in Python? var bytes:ByteArray = new
I have python code below that will loop through a table and print out
I have a python psp page code is shown below. Currently it only prints
I am trying to implement this package http://code.google.com/p/python-progressbar/ when downloading a file like below:
I have been trying to debug the below python cgi code but doesn't seems
I want to determine which attribute to look-up dynamicaly, Consider below python code: def
Please go through the python code snippet below import subprocess child = subprocess.Popen(python ./myprog.py
In the code below, I want to read obj.subject and place it into var
Below is python code where I am trying to get reservations information from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.