0

Python challenge question wrong - Why?

I was doing a Python challenge and the below question came up. When I ran the code myself, it came up with a syntax error. Does anyone know why? def evens(max): v = 0 while v <= max: yield v v+=2

16th Jan 2022, 11:18 AM
K Ka
5 Answers
+ 3
# Could be an indentation error def evens(max): v = 0 while v <= max: yield v v+=2
16th Jan 2022, 11:23 AM
Lisa
Lisa - avatar
0
Btw: Question was to put the missing word where yield was which i did, but the code comes up with a syntax error
16th Jan 2022, 11:18 AM
K Ka
0
Lisa Thank you! def evens(max): v = 0 while v <= max: yield v v+=2 if v >= 300: break print(evens(max)) This now outputs but not what i expected
16th Jan 2022, 12:55 PM
K Ka
0
What did you expect? In case you wanted a list, you would need to wrap it in list(): print(list(evens(10))) Here's a little demonstration of how evens() could be used: https://code.sololearn.com/cPsN1TsMB070/?ref=app
16th Jan 2022, 1:17 PM
Lisa
Lisa - avatar
0
Lisa i expected to get a result similar to # generator one that is on your code above. But for some reason this was the result i got with my code: <generator object evens at 0x7f10722723c0> P.s. Thank you, you are very helpful!
16th Jan 2022, 7:00 PM
K Ka