Spaces:
Running
Running
Create python_interpreter.py
Browse files- python_interpreter.py +19 -0
python_interpreter.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def simulate_python_interpreter():
|
2 |
+
print("Python 3.9.7 (default, Sep 3 2022, 02:21:24)")
|
3 |
+
print("[GCC 11.2.0] on linux")
|
4 |
+
print("Type 'help', 'copyright', 'credits' or 'license' for more information.")
|
5 |
+
|
6 |
+
while True:
|
7 |
+
try:
|
8 |
+
print(">>> ")
|
9 |
+
user_input = input()
|
10 |
+
if user_input.lower() == 'exit()':
|
11 |
+
print("Exiting Python interpreter simulator.")
|
12 |
+
break
|
13 |
+
result = eval(user_input)
|
14 |
+
print(result)
|
15 |
+
except Exception as e:
|
16 |
+
print("Error:", e)
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
simulate_python_interpreter()
|