Currency Program in Python
A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.
This program is written in the Python programming language and it is designed to accept an input from the user representing an amount to be withdrawn. Then, it calculates the number of hundred-rupee notes, fifty-rupee notes and ten-rupee notes required to withdraw the entered amount.
- It starts by using the "input()" function to accept a value from the user which is stored in a variable named "amt".
- The program then uses the "//" operator to divide the "amt" variable by 100, and assigns the quotient to the variable "hundred". This calculates the number of hundred-rupee notes required to withdraw the entered amount.
- The program then uses the modulus operator "%" to find the remainder of the division of "amt" by 100 and assigns it to the variable "amt". This is done because the remainder is used to calculate the number of fifty-rupee notes required.
- Then the program again uses the "//" operator to divide the updated "amt" variable by 50, and assigns the quotient to the variable "fifty". This calculates the number of fifty-rupee notes required to withdraw the entered amount.
- Then, the program uses the modulus operator again to find the remainder of the division of "amt" by 50, and assigns it to the variable "amt". This is done because the remainder is used to calculate the number of ten-rupee notes required.
- Then the program again uses the "//" operator to divide the updated "amt" variable by 10, and assigns the quotient to the variable "ten". This calculates the number of ten-rupee notes required to withdraw the entered amount.
- Finally, the program uses the "print()" function to display the number of hundred-rupee notes, fifty-rupee notes and ten-rupee notes required to withdraw the entered amount.
Source Code
amt = int(input("Enter the Amount to be Withdrawn :"))
hundred = amt//100
amt = amt%100
fifty = amt//50
amt = amt%50
ten = amt//10
print("No of Hundred Notes :",hundred)
print("No of Fifty Notes :",fifty)
print("No of Ten Notes :",ten)
Output
Enter the Amount to be Withdrawn :23570
No of Hundred Notes : 235
No of Fifty Notes : 1
No of Ten Notes : 2