Help - Python 26.2 - Let's Do Some Magic
Can anyone explain to me the third line of code? Why has the 'coach' used a "for" loop for a "while" loop question? I know that they are somewhat interchangeable, albeit "for" loops are more succinct. Where has the "i" come from? How can the program identify what "i" is without prior allocation? What does "range(days)" mean? Is "range" a function or a variable? If it's the latter how come it too has not been given a value? Can someone show me a solution to the question using "while"? QUESTION You have a magic box that doubles the count of items you put, in every day. The given program takes the initial count of the items and the number of days as input. Task Write a program to calculate and output items' count on the last day. Sample Input 3 2 Sample Output 12 Explanation Day 1: 6 (3*2) Day 2: 12 (6*2) CODE items = int(input()) days = int(input()) for i in range(days): items *= 2 print(items)