Advertisement
timber101

Untitled

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