python_shell.py

Created by wperez274

Created on September 26, 2023

818 Bytes


#Simple Python Shell
#Designed By: Wilson
#Written By GPT-3
from math import *
from cmath import *


error_dict = {
    'ZeroDivisionError': 'Cannot divide by zero.',
    'NameError': 'Name not defined.',
    # Add other errors here
}

while True:
    user_input = input(">>> ")
    if user_input == "exit":
        break

    # Check if the input is an expression
    if any(char in "+-*/" for char in user_input):
        try:
            result = eval(user_input)
            print(result)
            continue
        except Exception as e:
            error_type = type(e).__name__
            print(error_type)
            continue

    # For other code execution
    try:
        exec(user_input)
    except Exception as e:
        error_type = type(e).__name__
        print(error_type)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.