Python Core Lesson 26.2 "let's do some magic" | Sololearn: Learn to code for FREE!

-1

# Python Core Lesson 26.2 "let's do some magic"

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) I am having a really hard time with this. The variable placement is not computing in side my mind. Items = int(input()) Days = int(input()) While days > 0: Days += 1 Items = days + items * 2 Print items I am generally having a difficult time with while loops I've completed 1 lesson but the other 4 are a pain. Thanks for your help. :)

9/10/2021 10:55:06 PM

Michael

+4

Ok, that's nearby ๐ while days > 0 is ok. But then you can't count up the days. This loop will never end. Count them down: days - = 1 Then double the items each day: items *= 2 You can't add items and days, that makes no sense. Then print items, but not in the loop! And take attention to name all variables lower case. Don't mix days and Days or items and Items.

0

That totally worked. Ugh I was so close. I had tried the items *= 2 before but never did the days -= 1 ! That's so weird! I also think it's odd that in some of the examples before this lesson they printed within the loop. I've been working on this loop for several days, it's almost as if I kept pushing further away the more I tried. I have to remember to keep it simple. Thank you so much!

0

Your are welcome. And I know that. Some things took a while. But one day it becomes easy. Keep on coding ๐โโ๏ธ

0

This works for me: items = int(input()) days = int(input()) #your code goes here while days > 0: days -= 1 items *= 2 if days == 0: print(items) If you have any question just ask!

0

Hello Stefan, thank you for your answer. Please, I don't understand the if days == 0: How could I interpretate in order to understand it? Thank you