Answer:
<em>num_ones = amount_to_change % 5</em>
Explanation:
It is given that the cashier has to change the money in the maximum number of 5 dollar bills and remaining as $1 bills.
We have to write a single statement of code to assign the value to variable <em>num_ones </em>to find the value of $1 bills given <em>amount_to_change.</em>
<em />
Let us solve this by taking example:
If <em>amount_to_change </em>= $19
Then total number of $5 bills that can be given is 3. And amount that can be given as $5 bills is
So, the remaining amount i.e. $19 - $15 = $4 will be given as one dollar bills.
Out of these $19, 4 bills of $1 can be found using the <em>Modulus (%) operator.</em>
<em></em>
Modulus operator leaves the remainder i.e.
Output of <em>p % q </em>is the remainder when a number 'p' is divided by 'q'.
19 % 5 = 4
4 is the number of one dollar bills to be given.
So, single line of code for the number of one dollar bills can be written as:
<em>num_ones = amount_to_change % 5</em>
<em />
<em />
Let us try it for <em>amount_to_change = </em>$30
We know that 6 number of $5 bills can be used to change the amount of $30 and no one dollar bill required.
<em>num_ones = 30 % 5 = </em>0 (because 30 is completely divisible by 5 so remainder is 0)
So, the correct statement is:
<em>num_ones = amount_to_change % 5</em>