Advertisement

# Untitled

May 8th, 2019
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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? ")
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. else:
82.     print ("sorry i dont understand your data entry :- " + command)
Advertisement
RAW Paste Data Copied
Advertisement