Can anyone help me in the code coach problem 26.2 in Python Core? | Sololearn: Learn to code for FREE!

+8

Can anyone help me in the code coach problem 26.2 in Python Core?

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) Use *= operator to multiply the count of the items by 2 in each iteration. My code: items = int(input()) days = int(input()) while days > 0: days -= 1 items = days + items * 2 print(items)

3 Answers

New Answer

+5

ANSHU KHANRA | Solohelper , 2 issues, see your code with comments: .... while days > 0: days -= 1 items = items * 2 # formula reworked print(items) # output should done only once, not in each iteration. removed indentation happy coding and good success!

+7

Can anyone tell me what is the problem in this code?

+6