196k views
3 votes
Help me with this coding question that involves "For Loop"

Help me with this coding question that involves "For Loop"-example-1
User Poige
by
5.0k points

1 Answer

4 votes

Answer:

FIXED_COST = 1.24

FREE_MINUTES = 3

COST_PER_MINUTE = 0.76

print( "----------------- Chow Mobile -----------------" )

total = 0

nrCalls = int(input('\\Number of long distance phone calls made: '))

for i in range(nrCalls):

minutes = int(input('\\Number of minutes for call #{}: '.format(i+1)))

cost = FIXED_COST

if minutes > FREE_MINUTES:

cost += (minutes - FREE_MINUTES)*COST_PER_MINUTE

total += cost

print('\\Cost for call #{}: ${:,.2f}'.format(i+1, cost))

print('Total cost of all calls: ${:,.2f}'.format(total))

print( "-------------- THANK YOU --------------" )

Step-by-step explanation:

I have improved the display of currency to always use 2 digits. All constants are defined at the top, so that you don't have "magic numbers" inside your code. This makes the purpose of the numbers also more clear.

User Malavika
by
4.4k points