Nov-30-2019, 08:41 PM
(This post was last modified: Nov-30-2019, 09:03 PM by ichabod801.)
I'm a beginner and I'm struggling with the following task:
Write a program that will add up the cost of several items. The program should ask the user to enter how many items there are, and then ask for the price of each item with the prompt message in the form “Please enter the price of the item: £”. The user enters the price of each item as a number without a currency symbol. The program should add the prices together and then display the total cost with a user-friendly message, including the currency symbol, £.
Challenge: Develop your program further so that the user enters the amount that they have paid (e.g. 20.00 without the £ symbol) and the program displays how many £20, £10, £5 notes and how many £2, £1, 50p, 20p, 10p, 5p, 2p and 1p coins should be given as change, or how much more money is needed.
For the above challenge, the // operator (floor division, or integer division) and % modulo operator (gives the positive remainder from integer division) are helpful.
e.g.
5 // 2 = 2 (the integer part of the division calculation)
5 % 2 = 1 (the remainder from integer division)
So far I have...
# Adding items
Any help would be greatly appreciated thanks
Write a program that will add up the cost of several items. The program should ask the user to enter how many items there are, and then ask for the price of each item with the prompt message in the form “Please enter the price of the item: £”. The user enters the price of each item as a number without a currency symbol. The program should add the prices together and then display the total cost with a user-friendly message, including the currency symbol, £.
Challenge: Develop your program further so that the user enters the amount that they have paid (e.g. 20.00 without the £ symbol) and the program displays how many £20, £10, £5 notes and how many £2, £1, 50p, 20p, 10p, 5p, 2p and 1p coins should be given as change, or how much more money is needed.
For the above challenge, the // operator (floor division, or integer division) and % modulo operator (gives the positive remainder from integer division) are helpful.
e.g.
5 // 2 = 2 (the integer part of the division calculation)
5 % 2 = 1 (the remainder from integer division)
So far I have...
# Adding items
print (" How many items do you have?") numberofitems = input() item_1 = float(input('Enter the first items price £: ')) item_2 = float(input('Enter the second items price £: ')) print(item_1 + item_2)How do I make the users input, the number of times the program asks for the price?
Any help would be greatly appreciated thanks