I have made a code. It works like we are running the original python. It uses eval
and exec
. When I try to make a function or any if
statement in it ,it don't works. Here is the code:
print("Python
")
while True:
command =input(">>> ")
if command == "quit()":break
try:
try:
eval(command)
except:
exec(command)
except Exception as err:
print("Exception: "+str(err))
Running:
Python
>>> a = input("Enter your name: ")
Enter your name: abc
>>> print(a)
abc
>>> if True:
Exception: unexpected EOF while parsing (<string>, line 1)
>>> if True:print(a);if a == "abc":print("Great Abc")
Exception: invalid syntax (<string>, line 1)
>>>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…