Why is my loop stopping after one iteration? (python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Why is my loop stopping after one iteration? (python)

items = int(input()) days = int(input()) #your code goes here x = 1 total = 0 while x <= days: total = days * items x = x + 1 print(total)

30th Nov 2021, 3:25 AM
Evan Bain
Evan Bain - avatar
6 Answers
+ 2
It is all depend on what u have enter in days (input). when u enter 1 to days ur program will run just one iteration
30th Nov 2021, 4:33 AM
Pranshu Sachan
+ 2
IMHO it should be total+=days*items
30th Nov 2021, 7:04 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
It depends on the value of days.
30th Nov 2021, 3:27 AM
Simon Sauter
Simon Sauter - avatar
+ 1
What are you trying to do?
30th Nov 2021, 3:29 AM
Simon Sauter
Simon Sauter - avatar
+ 1
It's not stopping, you're doing the same thing on every iteration.
30th Nov 2021, 3:30 AM
zexu knub
zexu knub - avatar
+ 1
1- it depends on the days input 2- you are just repeating the same thing because days and items are not changing 3- the print is outside the loop so it will only print the last iteration
30th Nov 2021, 5:21 AM
Abdulaziz Al-Shehhi
Abdulaziz Al-Shehhi - avatar