Python Forum
I am new to python , i am confused with this syntax , please help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am new to python , i am confused with this syntax , please help
#1
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
Reply
#2
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")
Reply
#3
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.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
i got it now and Thank you very much for your response and suggestion
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas confused DPaul 6 196 Sep-19-2021, 06:45 AM
Last Post: DPaul
  is and '==' i'm confused hshivaraj 6 342 Sep-15-2021, 09:45 AM
Last Post: snippsat
  Confused with 'flags' tester_V 10 1,277 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Simple Tic Tac Toe but I'm confused Izith 1 646 Sep-26-2020, 04:42 PM
Last Post: Larz60+
  I am really confused with this error. Runar 3 827 Sep-14-2020, 09:27 AM
Last Post: buran
  Confused by 'break' in the official documents Chuck_Norwich 2 847 Apr-12-2020, 09:26 PM
Last Post: Chuck_Norwich
  Confused on how to go about writing this or doing this... pythonforumuser 3 969 Feb-10-2020, 09:15 AM
Last Post: snippsat
  I always get 'None' returned. Confused. What did I miss? jpezz 2 1,079 Apr-07-2019, 10:06 AM
Last Post: jpezz
  Confused by order of operations ward 4 1,255 Jan-22-2019, 08:53 PM
Last Post: Larz60+
  Confused by this modulo equation VikramSuh 3 1,473 Sep-05-2018, 12:43 PM
Last Post: VikramSuh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020