Allen Chen

Generation

code to explanationSun, 02 Apr 2023

def food_timer(food,seconds): return food + int(seconds / 10) def iron_timer(iron,seconds): return iron + int(seconds / 100) def army_timer(food,seconds): return food - int(seconds / 60) def survival(food, iron, seconds): army = True while army: print(food,iron) food = food_timer(food,seconds) iron = iron_timer(iron,seconds) food = army_timer(food,seconds) if food <= 0: print('You are dead') army = False if iron <= 0: print('You lost the war') army = False survival(100,100,100000)

The function survival takes three arguments food, iron, and seconds. Define the variable army to True and create a while loop. The while loop takes the food, iron, and seconds. The while loop prints the value of food and iron. The while loop uses the function food_timer, iron_timer, and army_timer to update the value of food and iron. If the value of food is less than or equal to zero print 'You are dead'. If the value of iron is less than or equal to zero print 'You lost the war.

Questions about programming?Chat with your personal AI assistant