-4

Error:

Traceback (most recent call last):
File "python", line 2
if Number == "50" and "51" and "52" and "53" and "54" and "55" and "56 "and "57" and "58" and "59" and "60":
 ^
IndentationError: unexpected indent

Code:

Number = input ("Please enter a number between 50 and 60: ")
    if Number == "50" and "51" and "52" and "53" and "54" and "55" and "56 "and "57" and "58" and "59" and "60":
print ("The number ") + (Number) + (" is with in range")

I'm trying to run this python code but i keep getting error message "unexpected indent". I'm not sure whats wrong. The spacing seem to be fine. Any idea's?

Josh Hunt
  • 29
  • 4

3 Answers3

3

Your indentation is backwards. The line after the if should be indented.

Number = input ("Please enter a number between 50 and 60: ")
if Number == "50" and "51" and "52" and "53" and "54" and "55" and "56 "and "57" and "58" and "59" and "60":
    print ("The number ") + (Number) + (" is with in range")
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • 3
    I can't in good conscience upvote this knowing you didn't address the faults in the condition itself. – Sterling Archer Apr 20 '15 at 16:03
  • 1
    For the record, I 100% endorse Bhargav's comment linking to http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values :-) – Kevin Apr 20 '15 at 16:04
  • i'm new to python i don't know how to code but i'm trying my best to learn it thank for the help. – Josh Hunt Apr 20 '15 at 16:12
2

Have you indented the line after if with four spaces ? Please note there is a logic flaw in your code; your if statement will never be true. Did you mean to use or instead? In that case you can implement it more efficient using this code snippet:

Number = input ("Please enter a number between 50 and 60: ")
if 50 <= Number <= 60:
    print ("The number ") + (Number) + (" is with in range")
Alex
  • 21,273
  • 10
  • 61
  • 73
  • You need to convert the return value of `input()` to an integer, in Python 3. Not that that `print()` line would work in Python 3... – Martijn Pieters Apr 20 '15 at 16:05
0

You have your if statement indented and your print not indented. It should be the other way around. Also, as previous folks have noted, your if statement is incorrect, which will generate another error.:

Number = input("Please enter a number between 50 and 60: ")
if Number in ['50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60']:
    print("The number %s is within range" % Number)

I'm not sure why you're treating the number as a string, though. I'd do it as:

try:
    Number = int(input("Please enter a number between 50 and 60: "))
except ValueError:
    print("You were supposed to enter a number!")
else:
    if 50 <= Number <= 60:
        print("The number %d is within range" % Number)
Deacon
  • 3,615
  • 2
  • 31
  • 52