Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. print("Hello! Let's get to work.")
  2. # users_name = input("Please enter your preferred name to begin")
  3. # print("Welcome " + users_name)
  4. command =input("How can I help? ")
  5. if command == "add":
  6. print("let's add some numbers")
  7. input1 = input("Number 1> ")
  8. input2 = input("Number 2> ")
  9. number1 = int(input1)
  10. number2 = int(input2)
  11. result = number1 + number2
  12. output = str(result)
  13. print(input1 + " + " + input2 + " = " + output)
  14. elif command == "subtract":
  15. print("let's subtract some numbers")
  16. input1 = input("Number 1> ")
  17. input2 = input("Number 2> ")
  18. number1 = int(input1)
  19. number2 = int(input2)
  20. result = number1 - number2
  21. output = str(result)
  22. print(input1 + " - " + input2 + " = " + output)
  23. elif command == "multiply":
  24. print("let's multiply some numbers")
  25. input1 = input("Number 1> ")
  26. input2 = input("Number 2> ")
  27. number1 = int(input1)
  28. number2 = int(input2)
  29. result = number1 * number2
  30. output = str(result)
  31. print(input1 + " * " + input2 + " = " + output)
  32. elif command == "divide":
  33. print("let's divide some numbers")
  34. input1 = input("Number 1> ")
  35. input2 = input("Number 2> ")
  36. if input2 == "0":
  37. print("Number 2 is invalid, as division by zero is undefined.")
  38. print("Please input a different value for Number 2")
  39. input2 = input("Number 2> ")
  40. number1 = int(input1)
  41. number2 = int(input2)
  42. result = number1 / number2
  43. output = str(result)
  44. print(input1 + " / " + input2 + " = " + output)
  45. elif command == "average":
  46. number_total = input("How many numbers do you want to average (please input a numeral)? ")
  47. number_total = int(number_total)
  48. average_list = []
  49. running_total = 0
  50.  
  51. for current_number in range(number_total):
  52. input_number = input("Number " + str(current_number + 1) + " > ")
  53. average_list.append(input_number)
  54. running_total = running_total + int(input_number)
  55. output = running_total / len(average_list)
  56.  
  57. str_total = " "
  58. for list_number in range(len(average_list)):
  59. new_str = str(average_list[list_number])
  60. if list_number == 0:
  61. str_total = str_total + new_str
  62. else: str_total = str_total + " + " + new_str
  63. print("The average of (" + str_total + " ) / " + str(len(average_list)) + " = " + str(output))
  64.  
  65. else:
  66. print("I can't understand. Please only give commands to 'add', 'subtract', 'multiply', 'divide', or 'average'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement