Python Forum

Full Version: I am new to python , i am confused with this syntax , please help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Below are the script i have executed and i don't know what the issue is , please help

value = eval(input("Please enter an integer value in the range 0...10: ")
if value >= 0 and value <= 10:
print("In range")
print("Done")

Error
if value >= 0 and value <= 10:
^
SyntaxError: invalid syntax

Process finished with exit code 1

Never mind , i got the answer
value = int(input("Please enter an integer value in the range 0...10: "))
if value >= 0 and value <= 10:
    print("In range")
else:
    print("Not in range")
print("Done")
if value >= 0 and value <= 10:
You can write this in a nicer way:
if 0 <= value <= 10:
The error was in the first line. A missing parenthesis.
Don't use eval together with user input.
User input is always evil! Don't trust it blind.

eval executes expressions like shutil.rmtree('/home/user/').
eval does not execute statements. So eval('import os') throws an exception.
More dangerous and powerful is exec, which executes also statements.
i got it now and Thank you very much for your response and suggestion