Issue2201
Created on 2008-02-28 16:42 by str8lazy, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg63096 - (view) | Author: Jarod (str8lazy) | Date: 2008-02-28 16:42 | |
Section 4.4 of the tutorial gives example code:
>>> for n in range(2, 10):
... for x in range(2, n):
... if n % x == 0:
... print n, 'equals', x, '*', n/x
... break
... else:
... # loop fell through without finding a factor
... print n, 'is a prime number'
...
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
When one is to enter the code (print n, 'equals' x, '*' n/x) you are
given syntax error: File "<stdin>", line 4
print n, 'equals' x, '*' n/x
^
SyntaxError: invalid syntax
|
|||
| msg63097 - (view) | Author: Robert Lehmann (lehmannro) * | Date: 2008-02-28 17:01 | |
In the example code from the tutorial you gave, there was still a comma separator between the string 'equals' and the reference `x`. This is missing when you entered the code, that's why Python is throwing an exception there. |
|||
| msg63098 - (view) | Author: Jarod (str8lazy) | Date: 2008-02-28 17:47 | |
I made a type in that line, but when the typo isn't there I get the same thing. It turns out that it was an error from running a slightly older version of the dev kit. Now that I have updated the dev kit it runs, but I end up with the following as an output: 3 is a prime number 4 equals 2 * 2 5 is a prime number 5 is a prime number 5 is a prime number 6 equals 2 * 3 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 8 equals 2 * 4 9 is a prime number 9 equals 3 * 3 as opposed to the desired 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3 |
|||
| msg63103 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2008-02-28 18:39 | |
Sorry, but there must be another typo in your code. I guess the else clause isn't correctly indented -- it belongs to the "for" statement, not the "if" statement. |
|||
| msg63105 - (view) | Author: Jarod (str8lazy) | Date: 2008-02-28 20:11 | |
@Georg: you were correct, the indentation was incorrect, I suggest that there be some additional notation be added to code examples in the documentation showing how many tabs there are, to make for an easier read and minimize on errors. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:31 | admin | set | github: 46454 |
| 2008-02-28 20:11:39 | str8lazy | set | messages: + msg63105 |
| 2008-02-28 18:39:45 | georg.brandl | set | status: open -> closed resolution: not a bug messages: + msg63103 nosy: + georg.brandl |
| 2008-02-28 17:47:25 | str8lazy | set | messages: + msg63098 |
| 2008-02-28 17:01:45 | lehmannro | set | nosy:
+ lehmannro messages: + msg63097 |
| 2008-02-28 16:42:53 | str8lazy | create | |
