Advertisement
banjothorn

Untitled

Nov 1st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. def do_calculation():
  2. print("Lets " + command + " some numbers.")
  3. input1 = input("Number 1>")
  4. input2 = input("Number 2>")
  5. number1 = int(input1)
  6. number2 = int(input2)
  7. if command == "add":
  8. result = number1 + number2
  9. operator = " + "
  10. elif command == "subtract":
  11. result = number1 - number2
  12. operator = " - "
  13. output = str(result)
  14.  
  15. print(input1 + operator + input2 + " = " + output)
  16.  
  17.  
  18.  
  19. print("Hi I am John B, your personal bot.")
  20. print("lets get started.")
  21. print(" ")
  22. print(" ")
  23.  
  24. users_name = input("How would you like to be addressed? ")
  25. print(" ")
  26. print(" ")
  27. print("Welcome " + users_name + " and lets go on an adventure")
  28.  
  29. finished = False
  30. while finished == False:
  31. print("Available commands are - add or subtract or average or highest . ")
  32. print(" to stop the program enter quit.")
  33. command = input("Enter a command:- ")
  34. if command == "add" or command == "plus":
  35. do_calculation()
  36. elif command == "subtract":
  37. do_calculation()
  38. elif command == "average":
  39. how_many = input("How many numbers ? ")
  40. how_many = int(how_many)
  41. total = 0
  42. for number_count in range(how_many):
  43. number = input("Enter number " + str(number_count) + "> ")
  44. total = total+int(number)
  45. result = total/how_many
  46. print("The average = " + str(result))
  47. elif command == "highest":
  48. target = 0
  49.  
  50. how_many = input("How many numbers ? ")
  51. how_many = int(how_many)
  52. total = 0
  53.  
  54. for number_count in range(how_many):
  55. number = input("Enter number " + str(number_count) + "> ")
  56. # print("targ 1 " + str(target))
  57. if target < int(number):
  58. target = int(number)
  59. # print("targ 2 " + str(target))
  60.  
  61. print("The highest = " + str(target))
  62. elif command == "quit":
  63. finished = True
  64. else:
  65. print("sorry not a valid command")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement