Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- print "###############################################################################"
- print "####################+++Unvarying's Calculator+++###############################"
- print "###############################################################################\n"
- def dm_addition(n1, n2):
- add = n1 + n2
- return add
- def dm_subtraction(n1, n2):
- subtract = n1 - n2
- return subtract
- def dm_multiplication(n1, n2):
- multiply = n1 * n2
- return multiply
- def dm_division(n1, n2):
- divide = n1 / n2
- return divide
- def calc():
- print "Which operation would you like to perform?"
- while True:
- print "Operations are +, -, *, or /. Please enter operation below."
- opq = raw_input()
- if opq == "+":
- print "Addition selected!"
- while True:
- fq = raw_input("Would you like to have more than 2 numbers in this operation? (y/n): ")
- amount = []
- if fq == "y" or fq == "Y":
- while True:
- a = raw_input("How many numbers would you like to have in this operation? ")
- if a == "1":
- print "Error! Must be more than 2 numbers!"
- continue
- elif a == "2":
- print "Error! Must be more than 2 numbers!"
- else: break
- print "Appended!"
- print "Please enter the "+a+" numbers you would like to add below:"
- for x in range(0, + int(a)):
- x = int(raw_input(""))
- amount.append(x)
- print "\nAppended!"
- do_math = sum(amount)
- x = str(do_math)
- print "\nAnswer: "+x+"\n"
- while True:
- x_2 = raw_input("Would you like to continue using this calculator? (y/n) ")
- if x_2 == "n" or x_2 == "N":
- quit()
- elif x_2 == "y" or x_2 == "Y":
- return calc()
- elif fq == "n" or fq == "N":
- break
- else:
- print "Error! Answer must be Y or N!"
- continue
- n1 = int(raw_input("What will be the first number?: "))
- n2 = int(raw_input("What will be the second number?: "))
- time.sleep(0.2)
- print "Appended!"
- time.sleep(0.2)
- a = dm_addition(n1, n2)
- print "Answer: %s" % (a)
- time.sleep(0.2)
- while True:
- qq = raw_input("Would you like to quit? (y/n)")
- if qq == "y" or qq == "Y":
- quit()
- elif qq == "n" or qq == "N":
- print "Which operation would you like to perform?"
- break
- else:
- print "Error, please enter Y or N"
- continue
- elif opq == "-":
- print "Subtraction selected!"
- while True:
- fq = raw_input("Would you like to have more than 2 numbers in this operation? (y/n): ")
- amount = []
- if fq == "y" or fq == "Y":
- while True:
- a = raw_input("How many numbers would you like to have in this operation? ")
- if a == "1":
- print "Error! Must be more than 2 numbers!"
- continue
- elif a == "2":
- print "Error! Must be more than 2 numbers!"
- else: break
- print "Appended!"
- print "Please enter the "+a+" numbers you would like to subtract below:"
- for x in range(0, + int(a)):
- x = int(raw_input(""))
- amount.append(x)
- print "\nAppended!"
- do_math = reduce(lambda x, y: x-y, (amount))
- x = str(do_math)
- print "\nAnswer: "+x+"\n"
- while True:
- x_2 = raw_input("Would you like to continue using this calculator? (y/n) ")
- if x_2 == "n" or x_2 == "N":
- quit()
- elif x_2 == "y" or x_2 == "Y":
- return calc()
- elif fq == "n" or fq == "N":
- break
- else:
- print "Error! Answer must be Y or N!"
- continue
- n1 = int(raw_input("What will be the first number?: "))
- n2 = int(raw_input("What will be the second number?: "))
- time.sleep(0.2)
- print "Appended!"
- time.sleep(0.2)
- a = dm_subtraction(n1, n2)
- print "Answer: %s" % (a)
- time.sleep(0.2)
- while True:
- qq = raw_input("Would you like to quit? (y/n)")
- if qq == "y" or qq == "Y":
- quit()
- elif qq == "n" or qq == "N":
- print "Which operation would you like to perform?"
- break
- else:
- print "Error, please enter Y or N"
- continue
- elif opq == "*":
- print "Multiplication selected!"
- while True:
- fq = raw_input("Would you like to have more than 2 numbers in this operation? (y/n): ")
- amount = []
- if fq == "y" or fq == "Y":
- while True:
- a = raw_input("How many numbers would you like to have in this operation? ")
- if a == "1":
- print "Error! Must be more than 2 numbers!"
- continue
- elif a == "2":
- print "Error! Must be more than 2 numbers!"
- else: break
- print "Appended!"
- print "Please enter the "+a+" numbers you would like to multiply below:"
- for x in range(0, + int(a)):
- x = int(raw_input(""))
- amount.append(x)
- print "\nAppended!"
- do_math = reduce(lambda x, y: x*y, (amount))
- x = str(do_math)
- print "\nAnswer: "+x+"\n"
- while True:
- x_2 = raw_input("Would you like to continue using this calculator? (y/n) ")
- if x_2 == "n" or x_2 == "N":
- quit()
- elif x_2 == "y" or x_2 == "Y":
- return calc()
- elif fq == "n" or fq == "N":
- break
- else:
- print "Error! Answer must be Y or N!"
- continue
- n1 = int(raw_input("What will be the first number?: "))
- n2 = int(raw_input("What will be the second number?: "))
- time.sleep(0.2)
- print "Appended!"
- time.sleep(0.2)
- a = dm_multiplication(n1, n2)
- print "Answer: %s" % (a)
- time.sleep(0.2)
- while True:
- qq = raw_input("Would you like to quit? (y/n)")
- if qq == "y" or qq == "Y":
- quit()
- elif qq == "n" or qq == "N":
- print "Which operation would you like to perform?"
- break
- else:
- print "Error, please enter Y or N"
- continue
- elif opq == "/":
- print "Division selected!"
- while True:
- fq = raw_input("Would you like to have more than 2 numbers in this operation? (y/n): ")
- amount = []
- if fq == "y" or fq == "Y":
- while True:
- a = raw_input("How many numbers would you like to have in this operation? ")
- if a == "1":
- print "Error! Must be more than 2 numbers!"
- continue
- elif a == "2":
- print "Error! Must be more than 2 numbers!"
- else: break
- print "Appended!"
- print "Please enter the "+a+" numbers you would like to divide below:"
- for x in range(0, + int(a)):
- x = int(raw_input(""))
- amount.append(x)
- print "\nAppended!"
- do_math = reduce(lambda x, y: x/y, (amount))
- x = str(do_math)
- print "\nAnswer: "+x+"\n"
- while True:
- x_2 = raw_input("Would you like to continue using this calculator? (y/n) ")
- if x_2 == "n" or x_2 == "N":
- quit()
- elif x_2 == "y" or x_2 == "Y":
- return calc()
- elif fq == "n" or fq == "N":
- break
- else:
- print "Error! Answer must be Y or N!"
- continue
- n1 = int(raw_input("What will be the first number?: "))
- n2 = int(raw_input("What will be the second number?: "))
- time.sleep(0.2)
- print "Appended!"
- time.sleep(0.2)
- a = dm_division(n1, n2)
- print "Answer: %s" % (a)
- time.sleep(0.2)
- while True:
- qq = raw_input("Would you like to quit? (y/n)")
- if qq == "y" or qq == "Y":
- quit()
- elif qq == "n" or qq == "N":
- print "Which operation would you like to perform?"
- break
- else:
- print "Error, please enter Y or N"
- continue
- else:
- print "Error! Invalid operation selected! Please choose an operation from the list >>> +, -, *, or /."
- continue
- quit()
- calc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement