+ 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?
14 odpowiedzi
+ 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"
+ 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.
+ 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’
+ 1
items = int(input())
days = int(input())
#your code goes here
i=1
while i<=days:
items*=2
i=i+1
else:
print(items)
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.
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!
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
0
items = int(input())
days = int(input())
count = 1
while count <= days:
items *= 2
count += 1
result = items
print(result)
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 .
0
items = int(input())
days = int(input())
#your code goes here
i=1
while i<=days:
items=items*2
i=i+1
print(items)
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)
0
count = 1
while count <= days:
items *= 2
count += 1
print(items)
- 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:
- 1
items = int(input())
days = int(input())
i=1
while i<=days:
items*=2
i+=1
print(items)