Python IDE |
Like many a homework question attacked by an eHowian over the years, this one didn't make much sense to our staffers. Why would anyone want to do that, anyway? G. S., however, had to come up with an answer to that question for his introduction, so he said that,
"...a programmer may want to build lists of specific, recurring patterns of numbers. Or, rather, a programmer wishes to use a number generation algorithm as an input function."
According to the post, Jackson wants you to enter the following code into IDLE:
i=0 >>>while i <10:
i=10 >>>while i < 10: ... if i % 2 != 0: ... print i ... i = i + 1
The staffer most familiar with Python looked at the code, scratched his head, and said, "That's not Python code!" And then he thought about it for a while and said, "Looks like eHow screwed it up and G. S. didn't bother to correct them. What we think Jackson actually wrote would was,
i=0
while i <10:
if i % 2 != 0:
print i
i = i + 1
But the port from eHow to Techwalla hosed the formatting. Of course, G. S. didn't really need to add the three > symbols that are the IDLE prompt – that didn't help much, we are sure. Then again, we aren't sure why Jackson chose a while loop instead of a for loop, but that's probably a matter of choice. What we do think he screwed up is that it's unlikely that someone wants the first few odd integers: they probably want a random set of integers (unless this is truly a beginning Python assignment).
For that, we'd use the built-in pseudorandom number generator to dump out a few odd number in, say, the range 0 to 999:
import random
for a in range(0,10):
i = random.randint(0,999)
if i%2 == 0:
i+=1
print i
We'd like to think Jackson's not the Dumbass of the Day, but surely he could have done better (and Techwalla should be ashamed of itself!)
¹ As in Eric Idle, founding member of Monty Python.
copyright © 2019-2021 scmrak
DD - CODING
No comments:
Post a Comment