anyone know how to solve this ?
SaiKhun (5)

A farrier was contacted one Sunday and asked to shoe a horse. Because Sunday was his day off, the farrier advised the rider to come back tomorrow, and that it would cost $150. But the rider kept insisting that the horse needed to be shod immediately, until eventually the farrier wore down and made the following offer: he would shoe the horse for free, but the rider needed to buy the nails from him and would be charged $0.01 for the first nail, and twice the price of the previous nail for each nail after that (e.g. the second nail would cost $0.02, the third $0.04, and so on). Given that a horse needs four shoes, and each shoe needs six nails, complete the following program to determine the total cost for the rider. It just goes to show how quickly things can grow with exponential growth!

total_cost = 0
cost_of_nail = 1
for horse_foot in range(4):
for nail in range(6):

    # TODO: Add price of current nail to total_cost and determine the cost of the next nail

print("The total cost to shoe the horse would be ${0:.2f}".format(total_cost / 100))

You are viewing a single comment. View All