[Solved] How can I implement loop in this program?


Here is how you can use a loop to get input, and append the burger prices to a list:

burgerPrices = []

for n in range(3):
    burgerPrice = int(input())
    burgerPrices.append(burgerPrice)

cokePrice = int(input())
spritePrice = int(input())

current = [burgerPrice+cokePrice for burgerPrice in burgerPrices]+\
          [burgerPrice+spritePrice for burgerPrice in burgerPrices]

print(min(current) - 50)

Or even better, a list comprehension:

burgerPrices = [int(input()) for _ in range(3)]

cokePrice = int(input())
spritePrice = int(input())

current = [burgerPrice+cokePrice for burgerPrice in burgerPrices]+\
          [burgerPrice+spritePrice for burgerPrice in burgerPrices]

print(min(current) - 50)

solved How can I implement loop in this program?