Advertisement
timber101

Untitled

May 8th, 2019
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.79 KB | None
  1. #  my code for futurelearn course on programming
  2. #  created 22/04/2019 by CJW
  3. #  variables - usersname - holds the name entered by the user
  4. #               input1 - first number ( as text)
  5. #               input2 - second number ( as text)
  6. #               input3 - third number ( as text)
  7. #               result - input 1 + input 2
  8. #               number1 - integer of input1
  9. #               number2 - integer of input2
  10. #               number3 - integer of input3
  11. #               output - resut as a string
  12. # Purpose - calculates the area of a triangle
  13.  
  14. #  starts
  15. print ("Hi, I'm Esmeralda and am your personal bot")
  16. usersname = input("Whats your name?  " ) # gathers username
  17. print ("Great to see you again, " + usersname + " Lets begin")
  18. command = input("How can I help <add, subtract, divide, multiply, volume, average, bill_sharer>? ")
  19. if command == "add" or command == "plus":
  20.     print("lets add some numbers")
  21.     input1 = input("Please enter first number ") # first number
  22.     input2 = input("Please enter second number ") # second number
  23.     number1 = int(input1) # saves as an integer
  24.     number2 = int(input2) # saves as an integer
  25.     result = number1 + number2
  26.     output = str(result)
  27.     print(input1 + " + " + input2 + " = " + output)
  28. elif command == "subtract":
  29.     print("lets subtract some numbers")
  30.     input1 = input("Please enter first number ") # first number
  31.     input2 = input("Please enter second number ") # second number
  32.     number1 = int(input1) # saves as an integer
  33.     number2 = int(input2) # saves as an integer
  34.     result = number1 - number2
  35.     output = str(result)
  36.     print(input1 + " - " + input2 + " = " + output)
  37. elif command == "multiply":
  38.     print("lets multiply some numbers")
  39.     input1 = input("Please enter first number ") # first number
  40.     input2 = input("Please enter second number ") # second number
  41.     number1 = int(input1) # saves as an integer
  42.     number2 = int(input2) # saves as an integer
  43.     result = number1 * number2
  44.     output = str(result)
  45.     print(input1 + " x " + input2 + " = " + output)
  46. elif command == "divide":
  47.     print("lets divide some numbers")
  48.     input1 = input("Please enter first number ") # first number
  49.     input2 = input("Please enter second number ") # second number
  50.     number1 = int(input1) # saves as an integer
  51.     number2 = int(input2) # saves as an integer
  52.     result = number1 / number2
  53.     output = str(result)
  54.     print(input1 + " / " + input2 + " = " + output)
  55. elif command == "volume":
  56.     print("lets caclulate the volume of a cube")
  57.     input1 = input("Please enter first number - length ") # first number
  58.     input2 = input("Please enter second number - depth ") # second number
  59.     input3 = input("Please enter third number - height ") # third number
  60.     number1 = int(input1) # saves as an integer
  61.     number2 = int(input2) # saves as an integer
  62.     number3 = int(input3) # saves as an integer
  63.     result = number1 * number2 * number3
  64.     output = str(result)
  65.     print("A cube with dimensions " + input1 + " " + input2 + " " + input3 + " has a volume of " + output)
  66. elif command == "average":
  67.     count = 0 # list count
  68.     tot = 0 # running total of values entered
  69.     how_many = input("how many numbers do you want to average? ")
  70.     how_many = int(how_many)
  71.     listofentries = []
  72.     for item_number in range(how_many): #  loop to input numbers items
  73.         item = input("What is number " + str(item_number) +" ? > ")
  74.         listofentries.append(item)
  75.         tot = tot + int(item)
  76.         count = count +1
  77.     result = tot / count
  78.     print ("Average = " +str(result))
  79.     print ("numbers entered = > " + str(listofentries))
  80.    
  81. elif command == "bill_sharer":
  82.     count = 0 # number of items on the bill
  83.     tot = 0.00 # running total of the bill
  84.     peeps = 0 # number of people to split the bill by
  85.     listofentries = [] # bill items
  86.    
  87.     items = input ("how many items are there on the bill? > ")
  88.     items = int(items)
  89.     for item_number in range(items): #  loop to input bill items
  90.         item = input("What is item " + str(item_number) +" ? > ") # data entry
  91.         listofentries.append(item) # add to history
  92.         tot = float(tot) + float(item) # add to running total
  93.         count = count +1
  94.     peeps = input ("how many people need to split this bill? > ")
  95.     peeps = int(peeps)
  96.     result = tot / peeps
  97.     #  print('{:.2f}'.format(result)) # this line was to test formatting to 2DP
  98.     print ( "total bill is > £" + str(tot))
  99.     print ( "Between " + str(peeps) + " people thats £" + str('{:.2f}'.format(result)) + " each")
  100.     print ( "Remainder is > " + str(tot -(peeps * result))) # this doesnt work as always comes out as zero
  101.     print ( "these items were in the list > " + str(listofentries))
  102.  
  103. else:
  104.     print ("sorry i dont understand your data entry :- " + command)
Advertisement
RAW Paste Data Copied
Advertisement