[Tutor] Hello
Sibylle Koczian
nulla.epistola at web.de
Sun Apr 23 04:38:29 EDT 2023
Am 20.04.2023 um 09:50 schrieb mhysnm1964 at gmail.com:
> Bernard
>
> Loops are used to execute a piece of code based upon specific conditions
> (expressions) in the loop statement or within the code block itself. There
> is three basic loop structures in any language:
>
...
>
> The while loop is the 2nd basic loop. This loop performs the expression test
> before any of the code within the loop block. If true, then nothing is
> executed in the loop block. For example:
>
> A = 5
> While a >4:
> A -= 1
> Print (a)
>
> The expression "a > 4" is true because a is greater than 4. The count and
> print statements are not executed. Change the a variable and the expression
> to get different results.
>
Wrong. The code inside the while loop is executed as long as the
expression is true!
Moreover, your code crashes with a NameError: for my part I overlooked
your mix of A and a, both meaning the same variable. But my Python shell
was more careful, as it should be:
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> A = 5
>>> while a > 4:
... A -= 1
... print(a)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined. Did you mean: 'A'?
>>>
Bernard: additional lesson here, Python is case sensitive. And I didn't
find any mention of this at the beginning of the tutorial where I'd
expect it.
HTH
Sibylle
More information about the Tutor
mailing list