0

Generators in python: not able to print result help me finding bug

def topten(): n=1 while n<=10: sq=n*n yield sq n+=1 values=topten() for i in values: print(i) #Why output not coming help

28th Apr 2020, 6:21 PM
Hasnain Jeelani
Hasnain Jeelani - avatar
6 Respostas
+ 3
ISAAC G What did you mean by "interpreter mode" ? Python (cpython) is always an interpreter and you can not change it! You can run Python in interactive or script mode, but it will always output numbers regardless of rhe mode since code outputs them using print function.
29th Apr 2020, 2:55 PM
andriy kan
andriy kan - avatar
+ 3
Your code is valid. It should print squares of numbers. Maybe the code has wrong indentations which can't be seen here? Save your code in the code playground and post link here.
28th Apr 2020, 7:09 PM
andriy kan
andriy kan - avatar
+ 1
thanks for ur assistance its working might be code playground maintainence issue running on
28th Apr 2020, 7:50 PM
Hasnain Jeelani
Hasnain Jeelani - avatar
+ 1
You should have tried it in interpreter mode ! Try it in the other mode. It's working!
29th Apr 2020, 12:09 PM
ISAAC G
ISAAC G - avatar
0
yes might be due to runtime error or any indentation mark.
29th Apr 2020, 1:42 PM
Hasnain Jeelani
Hasnain Jeelani - avatar
0
actually the application was under maintainence and might be due to that was not printing output even no error appearingi i tried afterwards it worked thankz🙌🏻
29th Apr 2020, 3:11 PM
Hasnain Jeelani
Hasnain Jeelani - avatar