+ 1

[Solved] Could you check this out to tell me what it tries to teach by answering three questions about the given code? (Python)

1) "reverse is not defined"? ( I guess it was supposed to be putNumbers(100), down there) 2) Why is the word class picked here, why does the func name look like a class name, too? 3) There are easier ways to do this, so what harder case do you think this is an example of? What's the point? "Question: Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n. Hints: Consider use yield Solution: def putNumbers(n): i = 0 while i<n: j=i i=i+1 if j%7==0: yield j for i in reverse(100): print(i) " Taken from : https://github.com/zhiwehu/JUMP_LINK__&&__Python__&&__JUMP_LINK-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises%20for%20Python%203.md#question-20 Thanks a bunch.

19th Jun 2022, 1:06 AM
Korkunç el Gato
Korkunç el Gato - avatar
2 Respuestas
+ 4
1. I think so. Sure the intention is calling the defined function. 2. It seems the idea is to create a class and include the function as a method. Probably static. I see no point, but the explanation is obscure... The recomnended style for class names in Python is to start each word with capitals - CamelCase. Python style never uses javaCase. For functions (and variables, objects, etc.), the style is lower_case_with_underscores. 3. Maybe a more complex test (in place of "divisible by 7") inside the loop, a more complex loop exit condition and a more complex relationship between loop variable (i) and test variable (j). Only guessing here.
19th Jun 2022, 1:39 AM
Emerson Prado
Emerson Prado - avatar
+ 2
Emerson Prado Thanks a lot for the response. I think this person had put up this sort of questions to teach more syntax than anything else, then, much like most SL in course exercises. I mean I'll chalk the lack of elaboration in this question up to that, and just move on. Thanks for all the info. I did look up PEP sometime ago but even the most elementary stuff doesn't stick when not repeated. I seem to have mixed things up.
19th Jun 2022, 1:58 AM
Korkunç el Gato
Korkunç el Gato - avatar