Advertisement
lubattillah

totals and averages

May 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import math
  2. def basic_math():
  3. if command in mean:
  4. n = int(input("How many data do you have?: "))
  5. total = 0
  6. for count in range(n):
  7. data = int(input("Enter data number "+str(count)+":"))
  8. total+=data
  9. result=total/n
  10. print("the average of ",n,"numbers is: "+str(result))
  11. elif command in addition:
  12. n = int(input("How many data do you have?: "))
  13. total = 0
  14. for count in range(n):
  15. data = int(input("Enter data number "+str(count)+":"))
  16. total+=data
  17. result=total
  18. print("the addition of ",n,"numbers is: "+str(result))
  19. elif command in multiplication:
  20. n = int(input("How many data do you have?: "))
  21. product=1
  22. for count in range(n):
  23. data = int(input("Enter data number "+str(count)+":"))
  24. product*=data
  25. result=product
  26. print("the product of ",n,"numbers is: "+str(result))
  27. else:
  28. n = int(input("How many data do you have?: "))
  29. sumsquares=0
  30. sum=0
  31. for count in range(n):
  32. data = int(input("Enter data number "+str(count)+":"))
  33. sumsquares+=data*data
  34. sum+=data
  35. avg=sum/n
  36. result=sumsquares/n-avg
  37. result=math.sqrt(result)
  38. print("the standard deviation of ",n,"numbers is: "+str(result))
  39. finished=False
  40. while finished==False:
  41. print("Hi, I am Khamisi, your personal bot.")
  42. addition=["sum","add","plus","total","+"]
  43. multiplication=["multiply","times","*","product"]
  44. mean=["average","arithmetic mean","avg"]
  45. sd=["standard deviation","sd"]
  46. command=input("choose operation: ")
  47. if command in mean:
  48. basic_math()
  49. elif command in addition:
  50. basic_math()
  51. elif command in multiplication:
  52. basic_math()
  53. elif command in sd:
  54. basic_math()
  55. else:
  56. finished=True
  57. print("Sorry I don't understand this")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement