J
J
JleBLLla2020-11-26 23:23:06
Informatics
JleBLLla, 2020-11-26 23:23:06

USE Informatics 25 task (python). What is wrong in my program?

Task:
Write a program that searches among the integers belonging to the numerical interval [312614; 312651], numbers that have exactly six different natural divisors. For each number found, write these six divisors in six adjacent columns on the screen on a new line. Divisors in a string must be in ascending order.

For example, in the range [12; 15] exactly six different natural divisors have the number 12, so for this range the output on the screen should contain the following values:

1 2 3 4 6 12
--------------------- -------------------------------------------------- -------------------------------------------------- ----------------------------
Wrote the following program:

a = 312614
b = 312651
for i in range (a, b):
    ds = []
    for d in range (1, i):
        if (i % d == 0):
            ds.append(d)
            if len(ds) > 6:
                break
    if (len(ds) == 6):
        print (ds[0], ds[1], ds[2], ds[3], ds[4], ds[5])

-------------------------------------------------- -------------------------------------------------- ------------------------------------------------
But she does not output anything in principle, and the answer should be like this:
1 2 4 78157 156314 312628

1 3 9 34739 104217 312651
I don’t know what the reason is. Prior to this, an absolutely identical program only with different numbers displayed everything with a bang

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2020-11-26
@saboteur_kiev

if len(ds) is GREATER than six, abort

if len(ds) > 6:
break

if (len(ds) == 6):

if len(ds) IS 6, display it on the screen.
Maybe it's the logic

1
15432, 2020-11-26
@15432

Either do i + 1 here Or compare it with 5 here The number itself is also considered a divisor of itself
for d in range (1, i):
if (len(ds) == 6):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question