I’m a beginner following a free Python course on EDX and I’m having trouble with one exercise.
It should be noted that although the class can be followed for free as I am, there is a paid version of it which opens lots more of exercise pages and I did get a hint that some additional topics are learned through them so my problem is…I don’t know if the exercise I’m trying to solve can be resolved with only the knowledge I’ve acquired with free portion of the course?
Therefore, my question is, can you solve this using only variables, math, logical and boolean operators and if absolutely necessary, if statements?
Thanks!
amount = 17
#The variable above describes an amount of money measured in
#dollars. Imagine you want to select the bills (1-dollar bills,
#5-dollar bills, 10-dollar bills, etc.) that make up that
#amount of money. For example, 17 dollars is one $10, one $5,
#and two $1s.
#
#Write a program that will print out the bills needed to
#arrive at the amount shown above. Assume that we always want
#the maximum number of large bills: for example, for 17 dollars,
#we want one $10, one $5, and two $1s, not three $5s and two $1s.
#You may assume that the largest bill you have on hand is a
#$50-dollar bill.
#
#Your code should print the following (with the correct numbers
#based on the value of amount):
#
#Fifties: 0
#Twenties: 0
#Tens: 1
#Fives: 1
#Ones: 2
As you’ll have guessed, I’m a complete beginner.
So this is as far as I was able to get:
# create a variable for each bill starting with a value = 0
Fifties = 0
Twenties = 0
Tens = 0
Fives = 0
Ones = 0
# figure out how many bills of each can fit in the initial amount
Fifties = amount // 50
Twenties = amount // 20
Tens = amount // 10
Fives = amount // 5
Ones = amount // 1
# print out the results as requested by the exercise (although this is not yet the correct answer of course)
print("Fifties:", Fifties)
print("Twenties:", Twenties)
print("Tens:", Tens)
print("Fives:", Fives)
print("Ones:", Ones)
So that gives me the number of bills of each type that can fit in the given amount but then comes the challenge of telling the program that it must use the largest bills first…any hints please?
I get a feeling that the % operator could be useful as well but can quite fit in?