Skip to content

Section 4.4 tutorial #134056

Not planned
Not planned
@unixio

Description

@unixio

Bug report

Bug description:

# Add a code block here, if required

for n in range(2,10):
for x in range(2,n):
if n %x == 0:
print(n,'equals',x,'*',n/x)
break
else:
print(n,'is prime')
The following is output on Windows 11 with either py or as a def
3 is prime
4 equals 2 * 2
5 is prime
5 is prime
5 is prime
6 equals 2 * 3
7 is prime
7 is prime
7 is prime
7 is prime
7 is prime
8 equals 2 * 4
9 is prime
9 equals 3 * 3

Tried the following

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
if x == (n - 1):
print(n, 'is a prime number')

The output
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

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Activity

added
type-bugAn unexpected behavior, bug, or error
on May 15, 2025
unixio

unixio commented on May 15, 2025

@unixio
Author

Experienced programmer. Learning python. Test examples to learn

hugovk

hugovk commented on May 15, 2025

@hugovk
Member

Please don't open spam issues.

changed the title [-]Section 4.4 tutorial[/-] [+]spam[/+] on May 15, 2025
added and removed
type-bugAn unexpected behavior, bug, or error
on May 15, 2025
unixio

unixio commented on May 15, 2025

@unixio
Author
No description provided.
changed the title [-]spam[/-] [+]Section 4.4 tutorial[/+] on May 15, 2025
hugovk

hugovk commented on May 15, 2025

@hugovk
Member

You opened a bug report and then closed it.

Sorry, I didn't look closely at the report the first time, but this issue tracker is for bug reports in the Python programming language itself.

The code in section 4.4 of the tutorial works as advertised. Please could you open a topic in the help forum if you'd like assistance with your modified code?

https://discuss.python.org/c/help/7

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Section 4.4 tutorial · Issue #134056 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant