Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite0
sololearn while loops quiz
hello, i want someone to explain me this code in python. items = int(input()) days = int(input()) while days>0: items*=2 days-=1 print(items)
1 Réponse
0
# Create two variables items & days.
# Each variable is initialized with a single line of console input - input()
# The input is then cast to a integer int()
items = int(input())
days = int(input())
# Creates a loop, conidition is 'days greater than 0'
# While days is greater than zero, the loop will continue to run.
while days>0:
# Modifying the variables inside the loop, these happen on each run (iteration)
# items is multiplied by 2. The *= operator expands to (items = items * 2)
items*=2
# days is reduced by 1. The -= expands to (days = days - 1)
days-=1
# Printing out the result to the console, value of items.
print(items)