Advertisement
c0d3dsk1lls

Terminal Calculator

Jun 16th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. """ Calculator
  2. ----------------------------------------
  3. """
  4. def addition ():
  5.     print("Addition")
  6.     n = float(input("Enter the number: "))
  7.     t = 0
  8.     ans = 0
  9.     while n != 0:
  10.         ans = ans + n
  11.         t+=1
  12.         n = float(input("Enter another number (0 to calculate): "))
  13.     return [ans,t]
  14. def subtraction ():
  15.     print("Subtraction");
  16.     n = float(input("Enter the number: "))
  17.     t = 0
  18.     sum = 0
  19.     while n != 0:
  20.         ans = ans - n
  21.         t+=1
  22.         n = float(input("Enter another number (0 to calculate): "))
  23.     return [ans,t]
  24. def multiplication ():
  25.     print("Multiplication")
  26.     n = float(input("Enter the number: "))
  27.     t = 0
  28.     ans = 1
  29.     while n != 0:
  30.         ans = ans * n
  31.         t+=1
  32.         n = float(input("Enter another number (0 to calculate): "))
  33.     return [ans,t]
  34. def average():
  35.     an = []
  36.     an = addition()
  37.     t = an[1]
  38.     a = an[0]
  39.     ans = a / t
  40.     return [ans,t]
  41.  
  42. while True:
  43.     list = []
  44.     print(" The JimmYuLator")
  45.     print(" Simple Calculator in python Jimmy Blaize")
  46.     print(" Enter 'a' for addition")
  47.     print(" Enter 's' for substraction")
  48.     print(" Enter 'm' for multiplication")
  49.     print(" Enter 'v' for average")
  50.     print(" Enter 'q' for quit")
  51.     c = input(" ")
  52.     if c != 'q':
  53.         if c == 'a':
  54.             list = addition()
  55.             print("Ans = ", list[0], " total inputs ",list[1])
  56.         elif c == 's':
  57.             list = subtraction()
  58.             print("Ans = ", list[0], " total inputs ",list[1])
  59.         elif c == 'm':
  60.             list = multiplication()
  61.             print("Ans = ", list[0], " total inputs ",list[1])
  62.         elif c == 'v':
  63.             list = average()
  64.             print("Ans = ", list[0], " total inputs ",list[1])
  65.         else:
  66.             print ("Sorry, invilid character")
  67.     else:
  68.         break
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement