I made a Cool Calculator of a Concept ive seen a long time ago but i want to know if i can optimise something:
Code:
Code:
import os if os.name == "nt": cle = cls else : cle = "clear" lopi = 1 while lopi == 1: hadexception = bool(False) bob = 0 os.system(cle) print("Select Operation") print("1: add") print("2: subtract") print("3: multiply") print("4: divide") print("5: x to the power of y") print("6: divide and delete decimals") print("7: Calculate the Factorial of a Number") print(" Type exit to exit") choice = input("Enter choice(1/2/3/4/5/6/7): ") if choice == 'exit': exit() elif choice not in ['1', '2', '3', '4', '5', '6', '7']: print("Operation not supported") input("Press Enter to restart") elif choice == '7': try: num1 = int(input("Enter your number: ")) except: hadexception = bool(True) if hadexception == bool(True): print("Not a Valid Number") input("Press Enter to restart") else: stry = num1 while bob == 0: if not stry == 1: stry = stry-1 num1 = num1*stry else: print(num1) bob = 1 input("Press Enter to Restart") else: try: num1 = int(input("Enter first number: ")) except: hadexception = bool(True) if hadexception == bool(True): print("Not a Valid Number") input("Press Enter to restart") else: try: num2 = int(input("Enter second number: ")) except: hadexception = bool(True) if hadexception == bool(True): print("Not a Valid Number") input("Press Enter to restart") else: if choice == '1': print(num1,'+',num2,'=',(num1+num2)) input("Press Enter to restart") elif choice == '2': print(num1,'-',num2,'=',(num1-num2)) input("Press Enter to restart") elif choice == '3': print(num1,'*',num2,'=',(num1*num2)) input("Press Enter to restart") elif choice == '4': print(num1,'/',num2,'=',(num1/num2)) input("Press Enter to restart") elif choice == '5': print(num1,'^',num2,'=',(num1**num2)) input("Press Enter to restart") elif choice == '6': print(num1,'//',num2,'=',(num1//num2)) print("R:", num1%num2) input("Press Enter to restart") else: print("Operation not Supported") input("Press Enter to restart")Forgot Code Tags