Advertisement
David90278

Raspberry Pi - Programming 101 - Calculating Averages

Feb 26th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | None | 0 0
  1. # Introduce yourself to your visitor
  2. print("Hi, I am Rotellity, the Funky Maths bot.")
  3. print("I came, I saw, I added, subtracted, multiplied and calculated percentages!")
  4. # Ask the visitor a question.
  5. # Use inputs to collect their responses
  6. # Use number variables to convert the input replies into integers
  7. # Use output to convert the result into a string
  8. command = input("How can I help?")
  9. if command == "add" or command == "plus":
  10.     print("let's add some numbers")
  11.     input1 = input("Pick a number, any number!>")
  12.     input2 = input("Now pick a second number>")
  13.     number1 = int(input1)
  14.     number2 = int(input2)
  15.     result = number1 + number2
  16.     output = str(result)
  17.     print("Watch me add both numbers! " + input1 + " + " + input2 + " = " + output)
  18. elif command == "subtract" or command == "minus":
  19.     print("let's subtract some numbers")
  20.     input1 = input("Start by picking one number, any number!")
  21.     input2 = input("Now, pick a second number, any one will do!")
  22.     number1 = int(input1)
  23.     number2 = int(input2)
  24.     result = number1 - number2
  25.     output = str(result)
  26.     print("Watch me substract both numbers! " +input1 + " - " + input2 + " = " + output)
  27. elif command == "multiply" or command == "times":
  28.     print("let's multiply two numbers!")
  29.     input1 = input("Pick your first number")
  30.     input2 = input("Pick your second number")
  31.     number1 = int(input1)
  32.     number2 = int(input2)
  33.     result = number1 * number2
  34.     output = str(result)
  35.     print("Let's multiply! " +input1 + " x " + input2 + " = " + output)
  36. elif command == "average":
  37.     how_many = input("How many numbers?>")
  38.     how_many = int(how_many)
  39.     total = 0
  40.     for number_count in range(how_many):
  41.         number = input("Enter number " + str(number_count) + "> ")
  42.         total = total + int(number)
  43.     result = total / how_many
  44.     print("the average = " + str(result))
  45. else:
  46.     print("Sorry, I am but a simple maths bot. I do not understand your request.")
  47. print("Let's calculate your amount you spend on groceries")
  48. input1 = input("How much did you spend this week on groceries?")
  49. input2 = input("How much did you earn this week?")
  50. number1 = int(input1)
  51. number2 = int(input2)
  52. result = number1 / number2
  53. output = str(result)
  54. print("Groceries made up " +output + " percent of your budget for the week.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement