+ 4

Why i am getting an error ?? Need help pls

I am getting the result including the following error message # Error message <module> item = next(nums_iter) StopIteration # Here is the code nums = [3, 4, 5, 8, 10] nums_iter = iter(nums) while True: item = next(nums_iter) print(item)

16th Dec 2018, 7:22 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
7 Antworten
+ 3
Hi... StopIteration is an exception which is raised by next() method to tell that there is no more values present. There can be two solution for this : #using try catch nums = [3, 4, 5, 8, 10] nums_iter = iter(nums) try: while True: item=next(nums_iter) print(item) except StopIteration: pass #adding dummy item at last nums = [3, 4, 5, 8, 10] nums_iter = iter(nums) while True: item=next(nums_iter,'end') if item=='end': break else: print(item)
16th Dec 2018, 8:46 PM
Rishi Anand
Rishi Anand - avatar
0
Take code and try it in code window in sololearn and you will see it runs. I don't understood why you dislike my answer. When a code don't run, I tell that and I purpose a solution if I can.
16th Dec 2018, 10:07 PM
MBZH31
MBZH31 - avatar
0
attn: MBZH31 that's not how you help somebody just typing "No error". The way Rishi Anand helped me that's the way you do otherwise don't attempt. And by the way i don't know how you compile and run the code. The code does cause ar error.
16th Dec 2018, 10:15 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
0
🄼🄼🄷🄺 I copy and paste your code in sololearn application in the code window.and i run it. That's all Look and test https://code.sololearn.com/cWDjEq18SB42/?ref=app
16th Dec 2018, 10:23 PM
MBZH31
MBZH31 - avatar
0
Just let it go, please i can understand you been trying to prove there is no error. I clicked your link with my code and still same error. so you better check yourself
16th Dec 2018, 10:34 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
- 2
No error
16th Dec 2018, 7:48 PM
MBZH31
MBZH31 - avatar
- 4
Stop being rude MMHK
17th Dec 2018, 3:55 AM
Robin