Untitled
unknown
plain_text
a month ago
2.2 kB
4
Indexable
Never
# Variables logo = ''' _____________________ | _________________ | | | Pythonista 0. | | .----------------. .----------------. .----------------. .----------------. | |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. | | ___ ___ ___ ___ | | | ______ | || | __ | || | _____ | || | ______ | | | | 7 | 8 | 9 | | + | | | | .' ___ | | || | / \ | || | |_ _| | || | .' ___ | | | | |___|___|___| |___| | | | / .' \_| | || | / /\ \ | || | | | | || | / .' \_| | | | | 4 | 5 | 6 | | - | | | | | | | || | / ____ \ | || | | | _ | || | | | | | | |___|___|___| |___| | | | \ `.___.'\ | || | _/ / \ \_ | || | _| |__/ | | || | \ `.___.'\ | | | | 1 | 2 | 3 | | x | | | | `._____.' | || ||____| |____|| || | |________| | || | `._____.' | | | |___|___|___| |___| | | | | || | | || | | || | | | | | . | 0 | = | | / | | | '--------------' || '--------------' || '--------------' || '--------------' | | |___|___|___| |___| | '----------------' '----------------' '----------------' '----------------' |_____________________| ''' operations = { '+' : add, '-' : subtract, '*' : multiply, '/' : divide } # Functions def add(n1, n2): return n1 + n2 def subtract(n1, n2): return n1 - n2 def multiply(n1, n2): return n1 * n2 def divide(n1, n2): return n1 / n2 # Body n1 = None while True: print(logo) # Only ask user for n1 if we are not continuing from a previous calculation if not n1: n1 = float(input("What's the first number?: ")) for key in operations: print(key) operation = input("Pick an operation: ") n2 = float(input("What's the next number?: ")) result = operations[operation](n1, n2) print(f"{n1} {operation} {n2} = {result}") user_continue = input(f"Type 'y' to continue calculating with {result}, or type 'n' to start a new calculation: ") if user_continue == 'y': n1 = result else: n1 = None # Clear terminal print("\033c", end="") print(logo)
Leave a Comment