Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def do_calculation():
- print("lets " + command + " some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- if command == "add":
- result = number1 + number2
- operator = " + "
- elif command == "subtract":
- result = number1 - number2
- operator = " - "
- output = str(result)
- print(input1 + operator + input2 + " = " + output)
- def do_average():
- #use a for loop storing each number into an array keeping a count (maybe)?
- #sum the members of the array and divide by the number of members
- #display the result
- numbers = []
- how_many = input("how many numbers would you like to find the average or total for? ")
- how_many = int(how_many)
- for item_number in range(how_many):
- display_number = item_number + 1
- item = input("what is your number " + str(display_number) + "? ")
- numbers.append(int(item))
- count = 0
- for item in numbers:
- count = count + item
- result = count / how_many
- if command == "average":
- print("No. of items in basket : " + str(len(numbers)))
- print("The average of your " + str(len(numbers)) + " items is " + str(result))
- else:
- print("The total of the " + str(len(numbers)) + " numbers you entered is " + str(count))
- def do_total():
- item = int(0)
- item_number = int(0)
- total = int(0)
- while item != "End" and item != "end":
- display_number = item_number + 1
- item = input("what is your number " + str(display_number) + "? ")
- if item != "End" and item != "end":
- total = total + int(item)
- item_number = item_number + 1
- print("The total of the " + str(item_number) + " numbers you entered is " + str(total))
- print("Would you like to add or subtract two numbers or find the average or total of multiple numbers?")
- command = input("Enter 'add', 'subtract', 'average' or 'total' > ")
- if command == "add" or command == "subtract" or command == "average" or command == "total":
- if command == "add":
- do_calculation()
- elif command == "subtract":
- do_calculation()
- elif command == "average":
- do_average()
- elif command == "total":
- do_total()
- else:
- print("Try again and enter 'add', 'subtract', 'average' or 'total' ")
- print("Bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement