Tom_Jung

Python101_Functions_AddSubAvg

Jan 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. def do_calculation():
  2.  
  3. command = input("Enter a command to add or subtract or average: ")
  4. print("Let's", command, "some numbers")
  5.  
  6. if command == "add":
  7. number1 = int(input("Number 1: "))
  8. number2 = int(input("Number 2: "))
  9. result = number1 + number2
  10. print(number1, "+",number2, "=", result)
  11.  
  12. elif command == "subtract":
  13. number1 = int(input("Number 1: "))
  14. number2 = int(input("Number 2: "))
  15. result = number1 - number2
  16. print(number1, "-", number2, "=" , result)
  17.  
  18. elif command == "average":
  19. how_many = input("How many numbers do you want to average? ")
  20. how_many = int(how_many)
  21. total = 0
  22. for number_count in range(how_many):
  23. number = input("Enter number " + str(number_count) + " = ")
  24. total = total + int(number)
  25. result = total / how_many
  26. print("average is = " + str(result))
  27.  
  28. else:
  29. print("This command is not recognized. Bye.")
  30.  
  31. do_calculation()
Advertisement
Add Comment
Please, Sign In to add comment