While loops (Lesson 27.1) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

While loops (Lesson 27.1)

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. Use *= operator to multiply the count of the items by 2 in each iteration. Hi, pls help me to get the exact code for this. I just wrote as blw and it worked but I’d like to know how to use while loops in the code. Items(int(input) Days(int(input) Print(items*2**days)

18th Oct 2021, 8:45 AM
Mine _e
2 Answers
0
Mine _e while days > 0: items *= 2 days -= 1 Here items is your initial input which will be multiply by 2 after each iteration until days becomes 0.
18th Oct 2021, 8:49 AM
A͢J
A͢J - avatar
0
Please include more lines of code. It states the use of a while loop, so lets see your try with a while loop!
18th Oct 2021, 8:49 AM
Slick
Slick - avatar