+ 2

while Loops

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?

7th Oct 2021, 2:15 PM
Matt Webb
14 Réponses
+ 7
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"
27th Nov 2021, 6:22 AM
Angel Sanchez
+ 2
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.
7th Oct 2021, 2:21 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
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’
12th Oct 2021, 9:28 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
items = int(input()) days = int(input()) #your code goes here i=1 while i<=days: items*=2 i=i+1 else: print(items)
25th Apr 2022, 12:14 PM
ELMISANI
0
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.
7th Oct 2021, 11:43 PM
Jibraeel Abdelwahhab
Jibraeel Abdelwahhab - avatar
0
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!
12th Oct 2021, 6:17 AM
Matt Webb
0
while items > 0 and days > 0 : print(2**days*items) break it will give me a right solution Is it right ? I mean is there better way to do it
8th Nov 2022, 4:40 PM
R3MBO0O
0
items = int(input()) days = int(input()) count = 1 while count <= days: items *= 2 count += 1 result = items print(result)
15th Nov 2022, 7:57 AM
Pooja Patel
Pooja Patel - avatar
0
There is shorter code results for the problem without adding anything new. Here the following code: items = int(input()) days = int(input()) while 0 < days: items *= 2 days-=1 print (items ) While the statement is finished with its true data and becomes false,** items** will be store as its Final result and only print it .
4th Dec 2022, 10:31 PM
Angelo Lucchese
0
items = int(input()) days = int(input()) #your code goes here i=1 while i<=days: items=items*2 i=i+1 print(items)
5th Jan 2023, 11:38 AM
Rajnish Anand Singh
Rajnish Anand Singh - avatar
0
Try this one ; items = int(input()) days = int(input()) #your code goes here count = 1 while count<= days : items *=2 count +=1 print(items)
27th Jan 2023, 5:29 AM
Himasha Nethmini
Himasha Nethmini - avatar
0
count = 1 while count <= days: items *= 2 count += 1 print(items)
15th Apr 2023, 10:46 PM
AMINE MOUTAOUAKKIL
- 1
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:
12th Oct 2021, 7:17 AM
Matt Webb
- 1
items = int(input()) days = int(input()) i=1 while i<=days: items*=2 i+=1 print(items)
4th Oct 2022, 12:09 PM
Baguvix
Baguvix - avatar