+ 1
Infinite Loop. .. Please help!
Hello, please check the code. I've tried use "while d<=len(decr)+1" in line 18, but it didn't work - the cycle didn't stop! I resolved the problem using "try - except" construction, but didn't get what was the problem! Please, help! Thanks!! https://code.sololearn.com/c03esaSeFv0C/?ref=app
9 ответов
+ 2
Take a look at the code again. Replacing while True by while d < len(decr) - 1 will solve your issues...
while d < len(decr) - 1 makes you loop through decr
+ 4
Since you're modifying the string you are looping on, it is usually safer to start at the end and process to the beginning. That way the stuff you haven't touched remains fixed, while the stuff you have processed grows or shrinks.
+ 2
You need a break statement somewhere... The statement "while true" will make the loop run infintely unless there is break
+ 2
When you are done, please let me know if it solves the issue :)
+ 2
All right. Take a look at this code
https://code.sololearn.com/cedI6NBZvk7I/?ref=app
+ 2
Use http://pythontutor.com/ to visualise your code - if it ^stalls^ due to an infinite loop, it will help you to see where it is.
+ 1
Yembik, yes I've used "try - except" instead break. But before I tried "while d<=len(decr) +1" - so when d is becomes more then length of the list it have to stop - but it don't. I tried to return d - it is increasing infinitly. So, do you know where can be the problem?
+ 1
Your questions are absolutely not stupid! We were all beginners one day. And I was very happy to help :)
0
Thanks a lot! I started learning programming just 3 days ago, so I'm sorry if my questions are stupid