+ 2

Program outputs twice

items = int(input()) days = int(input()) i = 1 while i <= days: d = items * 2 ** days i +=1 print(d) Why does this program output twice? For example when you put 3 and 2 it outputs 12 and 12 in the next line

6th Oct 2021, 3:39 PM
Filip Gajko
Filip Gajko - avatar
3 ответов
+ 3
It's output twice or multiple time because you have putted the print statement inside the while loop and whatever the days value is putted by user it will print the result till that time. If you want to take print statement one time than print outside the loop items = int(input()) days = int(input()) i = 1 while i <= days: d = items * 2 ** days i +=1 print(d)
6th Oct 2021, 3:45 PM
MsJ
MsJ - avatar
+ 2
No problem it happens :>
6th Oct 2021, 3:47 PM
MsJ
MsJ - avatar
0
Thank you bro I was a little blind hahah
6th Oct 2021, 3:47 PM
Filip Gajko
Filip Gajko - avatar