The possible denominations of currency notes are 100,50,20 and 10. The amount A to be withdrawn is given as input.
Write a program to break the amount into minimum number of bank notes.
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#prompt the user to enter the amount to withdraw
Amount_to_withdraw = int(input("\nEnter the amount you want to withdraw: "))
#copy the amount withrawable to another variable
original_amount = Amount_to_withdraw
#Check if the amount is withdrawable i.e if it is divisible by 10
if Amount_to_withdraw%10!=0:
#if it is not equal to zero request the user to try again later and exit the program
print("Dear, customer the amount you want to withdraw cannot be disbursed based on our\n"
" denominations, please try again later")
else:
#if it is withdrawable now perform the operations
#calculate the number of the hundred notes
hundred_notes = Amount_to_withdraw//100
#update amount withrawable
Amount_to_withdraw = Amount_to_withdraw-(Amount_to_withdraw // 100 * 100)
# calculate the number of the fifty notes
fifty_notes = Amount_to_withdraw // 50
# update amount withrawable
Amount_to_withdraw = Amount_to_withdraw- (Amount_to_withdraw // 50 * 50)
# calculate the number of the twenty notes
twenty_notes = Amount_to_withdraw // 20
# update amount withrawable
Amount_to_withdraw = Amount_to_withdraw-(Amount_to_withdraw // 20 * 20)
# calculate the number of the ten notes
ten_notes = Amount_to_withdraw // 10
#Calculate the total minimum number of notes
total_number_of_notes = hundred_notes+fifty_notes+twenty_notes+ten_notes
#Lets print the minimum number of notes and the number of each note
print("\nThe minimum number of notes to withdraw "+str(original_amount)+" = "+str(total_number_of_notes))
print("\n100 Notes: "+str(hundred_notes))
print("50 Notes: "+str(fifty_notes))
print("20 Notes: "+str(twenty_notes))
print("10 Notes: "+str(ten_notes))
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment