Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 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 == "+":
  8. result = number1 + number2
  9. operator = " + "
  10. elif command == "-":
  11. result = number1 - number2
  12. operator = " - "
  13. output = str(result)
  14. print(input1 + operator + input2 + " = " + output)
  15.  
  16. def do_sum_average():
  17. total=0
  18. # Requests how many numbers are to be entered and average found
  19. how_many=input("how many numbers do you wish to "+ command + "? > ")
  20. how_many=int(how_many)
  21. # Requests numbers to be averaged
  22. for number_count in range(how_many):
  23. number_count=number_count+1
  24. number = input("Enter number " + str(number_count) + "> ")
  25. total = total + int(number)
  26. if command=="average":
  27. result = total / how_many
  28. else:
  29. result=total
  30. print("the " +command+" = " + str(result))
  31.  
  32. #This statement introduces the Bot by name
  33. print("Hi, I am Marvin, your personal Bot.")
  34. #
  35. finished=False
  36. # Seeks input and allocates to variable "command"
  37.  
  38. while finished==False:
  39. command=("")
  40. while command!="+" and command!="-" and command!="*" and command!="/" and command!="average" and command!="Temperature Conversion" and command !="Total" and command!="bye":
  41. #
  42. command=input("Select Function: +, -, *,/,average, Total, Temperature Conversion,bye ")
  43. #
  44. #Tests if Bot is to Add
  45. if command=="+":
  46. do_calculation()
  47. #
  48. #Tests if Bot is to subtract
  49. elif command=="-":
  50. do_calculation()
  51. #
  52. #Tests if Bot is to multiply
  53. elif command=="*":
  54. #Requests numbers
  55. print("enter your numbers")
  56. input1 = input("Number 1> ")
  57. input2 = input("Number 2> ")
  58. #converts to integer variables
  59. number1 = int(input1)
  60. number2 = int(input2)
  61. #completes calculation, converts result to string and prints
  62. result = number1 * number2
  63. output=str(result)
  64. print(input1 + " x " + input2 + " = " + output)
  65. #
  66. #Tests if Bot is to divide
  67. elif command=="/":
  68. #Requests numbers
  69. print("enter your numbers")
  70. input1 = input("Number 1> ")
  71. input2 = input("Number 2> ")
  72. #converts to integer variables
  73. number1 = int(input1)
  74. number2 = int(input2)
  75. #completes calculation, converts result to string and prints
  76. result = number1 / number2
  77. output=str(result)
  78. print(input1 + " / " + input2 + " = " + output)
  79. # Tests if bot is to average
  80. elif command=="average":
  81. do_sum_average()
  82.  
  83. elif command=="Total":
  84. do_sum_average()
  85. #
  86. # Tests if selection is Temperature Conversion
  87. elif command=="Temperature Conversion":
  88. temp_choice="0"
  89. while temp_choice !="1" and temp_choice!="2":
  90. temp_choice=input("Please select 1=Celsius to Fahrenheit 2=Fahrenheit to Celsius > ")
  91. if temp_choice=="1":
  92. tempc=input("Input Temp in Celsius> ")
  93. tempc_int=float(tempc)
  94. tempf_int=(tempc_int*9/5)+32
  95. tempf=str(tempf_int)
  96. print(tempc+" degrees Celsius = "+tempf+" degrees Fahrenheit")
  97. else:
  98. tempf=input("Input Temp in Fahrenheit> ")
  99. tempf_int=float(tempf)
  100. tempc_int=(tempf_int-32)*5/9
  101. tempc=str(tempc_int)
  102. print(tempf+" degrees Fahrenheit = "+tempc+" degrees Celsius ")
  103. elif command=="bye":
  104. finished=True
  105. else:
  106. print("Do not understand")
  107. print("Goodbye come back soon")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement