Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from decimal import * #I use the decimal format to ensure that the money is handled properly
- getcontext().prec = 2 #This tells the program how many decimal places to put on the end of things
- out20P=0 #Setting all my variables up
- out10P=0
- out5P=0
- out2P=0
- out1P=0
- out50p=0
- out20p=0
- out10p=0
- out5p=0
- out2p=0
- out1p=0
- left=0
- bill=1
- payment=0
- while payment<bill: #I use this loop to make sure the user has enough money
- #if they do not the program will ask for data again
- bill=Decimal(input("Enter the bill that needs to be paied"))
- payment=Decimal(input("Enter how much you paied in pounds and pence"))
- if payment<bill: #This is for if the user has not got enough money
- print("Invalid funds")
- left=payment-bill
- while left !=Decimal(0.00):
- print(left)
- if left>= 20: #If there is more than a £20 difference
- left-=20
- out20P+=1
- elif left>= 10: #If there is more than a £10 difference
- left-=10
- out10P+=1
- elif left>=5: #If there is more than a £5 difference
- left-=5
- out5P+=1
- elif left>=1: #If there is more than a £1 difference
- left-=1
- out1P+=1
- print(left)
- elif left>= 0.5: #If there is more than a 50p difference
- left-=Decimal(0.50)
- out50p+=1
- elif left>=0.2: #If there is more than a 20p difference
- left-=0.20
- out20p+=1
- elif left>=0.1: #If there is more than a 10p difference
- left-=0.10
- out10p+=1
- elif left>=0.05: #If there is more than a 5p difference
- left-=0.05
- out5p+=1
- elif left>= 0.02: #If there is more than a 2p difference
- left-=0.02
- out2p+=1
- elif left>= 0.01: #If there is more than a 1p difference
- left-=0.01
- out1p+=1
- else:
- print ("You should have",out20P," of £20s")
- print ("You should have",out10P," of £10s")
- print ("You should have",out5P," of £5s")
- print ("You should have",out2P," of £2s")
- print ("You should have",out1P," of £1s")
- print ("You should have",out50p," of 50ps")
- print ("You should have",out20p," of 20ps")
- print ("You should have",out10p," of 10ps")
- print ("You should have",out5p," of 5ps")
- print ("You should have",out2p," of 2ps")
- print ("You should have",out1p," of 1ps")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement