sololearn while loops quiz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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)

21st Jan 2023, 12:13 PM
Theorem
1 Answer
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)
21st Jan 2023, 12:45 PM
DavX
DavX - avatar