while Loops 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) Any ideas folks?
10/7/2021 2:15:01 PMMatt Webb
7 AnswersNew Answer
items = int(input()) days = int(input()) count = 1 while count <= days: items *= 2 count += 1 result = items print(result) You need to assign the result to a variable and print it. The solution you posted doesn't even need the while loop code block as the calculation is done via "a = a*2**b"
Hi! Put in some brain work and start start to code! At least begin with some pseudo code so we get something to start with, to see what kind of coding help you need.
Matt Webb Hi! Maybe this can be of some help to you: https://code.sololearn.com/c4mdEKEMinQe/?ref=app ’count += 1’ means ’count = count + 1’ ’result *= 2’ means ’result = result * 2’
Hello, this is a very easy problem. Use some problem solving skills to help. You already know that you have to double the value a certain number of times, so iterate over the number of days and double your items every loop. You already know you'll be using a while loop and you want to run as many times as there are days. I hope this makes the problem very clear for you.
The best thing is, I believe i get somewhere close. With all but one of the solutions correct, then the console freezes. I lose the code and have to start again :) Oh the joys!
items = int(input()) days = int(input()) #your code goes here i=1 while i<=days: items*=2 i=i+1 else: print(items)
a = int(input()) b = int(input()) #your code goes here a = a*2**b i=1 while i<=1: print(a) i=i+1 At least i finally figured it out. First one i've genuinely been stuck on and not been able to get my numb skull around :joy: