I'm trying to make an ATM-like program in Python. The idea is that the user inputs any amount of money and the minimum amount of bills (100, 50, 25, 10, 5) will be printed.
So for example:
Input: 258
expected output: "2 $100 Bills, 1 $50 Bill, 1 $5 Bill, 3 $1 Bills".
The program works for number that are multiples of 5, but I can't seem to get the $10 and $1 Dollar bills to behave the same way. Here is the code:
print("Hi! Welcome to Python Bank. \nHow much would you like to withdraw?")
amnt = int(input("Please input amount: "))
if amnt >= 100:
if amnt // 100 >= 2:
print(amnt // 100, "$100 Bills")
else:
print("1 $100 Bill")
if (amnt // 50) % 2 != 0:
print("1 $50 Bill")
if (amnt // 25) % 2 != 0:
print("1 $25 Bill")
if (amnt // 10) % 2 != 0:
print(amnt // 10, "$10 Bills")
if (amnt // 5) % 2 != 0 and (amnt // 25) % 2 == 0:
print("1 $5 Bill")
if (amnt // 1) % 2 != 1:
print((amnt // 1), "$1 Bills")
I'm using the (//) operator since it tells you how many of the number on the right is in the number on the left. Then used the (%) operator with (!= 0). This seems to work for 100, 50, 25, but not for 10 and 1. How can I tackle this?
Your logic is wrong. This is the correct way.
if amount >= 100:
print(amount // 100, '100$ notes')
amount = amount % 100
if amount >= 50:
print('1 50$ notes')
amount = amount % 50
And so on