177k views
3 votes
There are six items to be rung up in the cash register. The first item costs $15.00. Each item after that costs an additional $2.00. (item #2 costs $17, item #3 costs $19, etc.) Create Python program code using a for loop that will print the cost of each item, starting with the $15 item, and it will calculate and print the total cost. Your program should then use the sequence formula as an alternative way to calculate the total cost and print the result.

User Twibit
by
7.5k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

Below is the python code :

#using a for loop that will print the cost of each item

#first item cost is $15.0

item = [15.0]

tcost = 0.0

#for loop to print cost of each item and calculate total cost

for i in range(6):

tcost += item[i]

print('Cost of item ', (i+1), ' : $', item[i], sep = '')

item.append(item[i] + 2)

#print total cost

print('Total cost: $', tcost, sep = '')

print()

#Sequence formula to calculate the total cost

#total cost = n * ((first + last) / 2)

print('Calculating total cost using sequence formula')

tcost2 = 6 * ((15 + 25) / 2)

print('Total cost: $', tcost2, sep = ''

User Alphy
by
7.4k points