Jayteepix

Add/Subtract and Average

Oct 29th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #Adding or Subtracting two numbers including Averaging the chosen number of numbers
  2. print("Would you like to Add or Subtract two numbers or find the Average of multiple numbers?")
  3. operator = input("Enter 'A' for Add, 'S' for Subtract or 'AVG' for Averages > ")
  4. if operator == "A" or operator == "S" or operator == "AVG":
  5.  
  6. if operator == "A":
  7. input1 = input("Please enter your first number ")
  8. input2 = input("now enter your second number ")
  9. num1 = float(input1)
  10. num2 = float(input2)
  11. print("Add two numbers")
  12. result = num1 + num2
  13. output = str(result)
  14. print("The sum of " + input1 + " and " + input2 + " is " + output)
  15.  
  16. elif operator == "S":
  17. input1 = input("Please enter your first number ")
  18. input2 = input("now enter your second number ")
  19. num1 = float(input1)
  20. num2 = float(input2)
  21. print("Subtract two numbers")
  22. result = num1 - num2
  23. output = str(result)
  24. print("The subtraction of " + input1 + " and " + input2 + " is " + output)
  25.  
  26. elif operator == "AVG":
  27. how_many = input("How many numbers> ")
  28. how_many = int(how_many)
  29. total = 0
  30. for number_count in range(how_many):
  31. number = input("Enter number " + str(number_count) + "> ")
  32. total = total + int(number)
  33. result = total / how_many
  34. print("the average = " + str(result))
  35.  
  36. else:
  37. print("Try again and select 'A' / 'P' or 'AVG ")
  38. print("Bye")
Advertisement
Add Comment
Please, Sign In to add comment