Question:
I’ve read numerous posts on this, and I realise lots of people have asked this, but I can’t understand what I’m doing wrong. I’m trying to draw a grid with coordinates for a project I’m working on, and I was trying some code for generating it. I tryed this one, but I keep getting that error. What’s wrong with the code? I’ve tryed different indentations but it doesn’t work.^^The original q+a
Thanks to everyone who helped, I’m not sure why that code was posted considering it wouldn’t work anyway! Sorry for my misunderstanding, I haven’t used generators before. ๐
Answer:
Theyield
keyword is used to “return” a generator object from a functionStack Overflow Question on the yield keyword
It cannot be used outside a function, like in your code.
If this was under a
def
statement, then it would be fine, however there is no def
statement here, so it raises an errorAlso, not in relation to the question, but these lines won’t work:
stepsize
is a float, and the range
function only handles integers – it will say something like TypeError: 'float' object cannot be interpreted as an integer
If you have better answer, please add a comment about this, thank you!