Skip to content

Instantly share code, notes, and snippets.

@megamaz
Created April 22, 2020 03:18
Show Gist options
  • Save megamaz/82a49eefb634c1afebcf0c6ea7a9425d to your computer and use it in GitHub Desktop.
Save megamaz/82a49eefb634c1afebcf0c6ea7a9425d to your computer and use it in GitHub Desktop.
My very very first python personal code! I am so very proud to have found it again. Here I am, sharing it.
print("FUN FACT ABOUT THIS CALCULATOR!")
import random
print()
print("---------------------------------------------------------------------------")
fact = random.randint(1, 3)
if fact == 1:
print("This calculator has 70 lines of code!")
if fact == 2:
print("The exponant had an error, which was fixed after 5 days.")
if fact == 3:
print("This code uses 25 print statements, 4 inputs, 11 ifs, 9 elifs, 2 loops, 25 concatinations, over 5 variables, and 1 else statement.")
print("---------------------------------------------------------------------------")
print("First, you need to enter which type of math you want to do.")
print()
print("Type * if you want to multiply, / to divide, + to add, - to substract, ^ to do exponant, = for less than / more than / equal to, and | to do fractions")
print()
loop = 5
while not loop == 0:
mathTYPE = input("What type of math do you want to do? ")
num1 = int(input("Enter your first number: "))
num2 = int(input("Enter your second number: "))
print()
if mathTYPE == "*":
total = float(num1) * float(num2)
print(str(num1) + " x " + str(num2) + " = " + str(total))
elif mathTYPE == "/":
if num2 == 0:
total = 'infinity'
else:
total = float(num1) / float(num2)
print(str(num1) + " / " + str(num2) + " = " + str(total))
elif mathTYPE == "+":
total = float(num1) + float(num2)
print(str(num1) + " + " + str(num2) + " = " + str(total))
elif mathTYPE == "-":
total = float(num1) - float(num2)
print(str(num1) + " - " + str(num2) + " = " + str(total))
elif mathTYPE == "|":
print(" " + str(num1))
print("----")
print(" " + str(num2))
elif mathTYPE == "=":
if num1 < num2:
print(num1 + " < " + num2)
elif num1 > num2:
print(num1 + " > " + num2)
elif num1 == num2:
print(num1 + " = " + num2)
elif mathTYPE == "^":
expo = int(num2)
numex = int(num1)
while not expo == 1:
total = float(num1) * float(numex)
num1 = float(total)
expo = expo - 1
print(str(numex) + " to the power of " + str(num2) + " = " + str(total))
elif mathTYPE == "!":
num2 = int(num2)
while not num2 == 1:
num2 = int(num1) - 1
total = int(num2) * num1
num2 -=1
print(str(num1) + "! =" + str(total))
else:
print("You were supposed to type in -, +, *, |, ^, or / !!")
q = input("Yes or no: Do you want to use again? Y = yes, N = no ")
if q == "N" or q == "n":
loop = loop - 5
print()
print("Thanks for using my calculator.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment