[Tutor] Module Review

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Apr 15 15:59:31 EDT 2023


On Sun, 16 Apr 2023 05:46:50 +1200, dn via Tutor <tutor at python.org>
declaimed the following:

>On 16/04/2023 03.28, Thurman Hill wrote:
>> number = 2 # Initialize the variable
>> while number < 13: # Complete the while loop condition
>> print(number, end=" ")
>>      number +2 # Increment the variable
>> 
>> # Should print 2 4 6 8 10 12
>> 
>> this is what i have now but i think the assessment may have messed up 
>> its saying it takes more than 5 seconds
>> to process so i need a simpler solution.

>2 Did you copy-paste the code from the script? As above, it won't 
>work/has a syntax error.
>
	Presuming the code is exactly as posted, it has two, if not three
errors...

	Indentation being one of them. The other is logic, so not caught by the
interpreter (I actually thought it would produce some message, but it seems
the result of that statement is to execute, and throw away the result)

C:\Users\Owner>python junk.py
  File "C:\Users\Owner\junk.py", line 4
    print(number, end=" ")
    ^
IndentationError: expected an indented block after 'while' statement on
line 3

C:\Users\Owner>

	Fixing that lets the program run...

C:\Users\Owner>python junk.py
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
<SNIP>
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Traceback (most
recent call last):
  File "C:\Users\Owner\junk.py", line 4, in <module>
    print(number, end=" ")
KeyboardInterrupt
^C
C:\Users\Owner>

	The mention of "assessment" makes it sound like the OP is not running
the code on a local machine where they can see the results, but is making
submittals to some web-based course. With that indentation correction, the
"while" loop will never end, so I can see a background processor on a web
site reporting that the assignment is running over some allocated time
slot.

	A corrected version runs so fast, the clock used by time.time() doesn't
even increment on my system...



More information about the Tutor mailing list