36.7k views
5 votes
Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the number of single dollars that would have to be paid. python

User Lxhom
by
4.8k points

1 Answer

4 votes

Answer:

  1. price = 380
  2. dollar = (price // 100) + 1
  3. print(dollar)

Step-by-step explanation:

Presume the an item cost 380 cents and we set 380 to the variable price (Line 1). To estimate the number of single dollars to be paid, we can use // operator to divide price by 100 and we will get 3 (the remaining decimal point will be discarded). Then we add 3 by one. So the expression is

(price//100) + 1

*The reason we divide price by 100 is because 1 dollar = 100 cents

User Luca Braglia
by
4.3k points