Advertisement
GreatRaymondo

reuse

May 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 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. elif command == "subtract":
  10. result = number1 - number2
  11. output = str(result)
  12. if command == "add":
  13. print(input1 + " + " + input2 + " = " + output)
  14. elif command == "subtract":
  15. print(input1 + " + " + input2 + " = " + output)
  16.  
  17. finished = False
  18. while finished == False:
  19. print("Him I am Mr Biddle, your personal bot. ")
  20. command = input("How can I help?")
  21. if command =="add":
  22. do_calculation()
  23. if command =="subtract":
  24. do_calculation()
  25. elif command == "multiply":
  26. print("Lets multiply some numbers")
  27. input1 = input("Number 1> ")
  28. input2 = input("Number 2> ")
  29. number1 = int(input1)
  30. number2 = int(input2)
  31. result = number1 * number2
  32. output = str(result)
  33. print(input1 + " * " + input2 + " = " + output)
  34. elif command == "area":
  35. print("lets find out the area of this room")
  36. input1 = input("length> ")
  37. input2 = input("width> ")
  38. number1 = int(input1)
  39. number2 = int(input2)
  40. result = number1 * number2
  41. output = str(result)
  42. print(input1 + " * " + input2 + " = " + output)
  43. elif command == "average":
  44. how_many = input("how many numbers> ")
  45. how_many = int(how_many)
  46. total = 0
  47. for number_count in range(how_many):
  48. number = input("Enter number " + str(number_count) + ">")
  49. total = total + int(number)
  50. result = total / how_many
  51. print("the average = " + str(result))
  52. elif command=="shopping":
  53. shopping=[]
  54. how_many=input("How many items do you have in your shopping list")
  55. how_many=int(how_many)
  56. for item_number in range(how_many):
  57. item=input("what is item number " + str(item_number) + "?")
  58. shopping.append(item)
  59. for item in shopping:
  60. print(item)
  61. total=len(shopping)
  62. print("you have "+str(total)+" items in your shopping list")
  63. elif command == "bye":
  64. finished = True
  65. else:
  66. print("sorry I dont have a scooby")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement