How to substitute values in a list in order in Python

Asked 2 years ago, Updated 2 years ago, 19 views

In my previous question, I was taught how to express the number of repunits.

I want to use Python to express the number of repunits and solve integer problems

Next, I want to substitute prime numbers in order, but I can't write the code well.
Specifically, you can put a prime number below the specified number in the list.
After following the previous question, I named the list p, but I don't know how to substitute the values in that p in order.

Here's a quote from a previous question:

I'd like to solve the problem of finding a prime p that is divisible by the following formula, but I don't know how Python handles the number of repunits.

1+10+10^2+...+10^(p-1)

Also, I know that the number of replicates can be expressed as int('1'*p).

Here's the code.

import path

defisPrime (num):
    if num<2—Return False
    elif num==2 —Return True
    elif num%2 == 0 —Return False

    for i in range(3,math.floor(math.sqrt(num)) +1,2):
        if num%i == 0:
            return False

    return True

def callIsPrime(input_num=1000):
    numbers = [ ]
   
    for i in range (1, input_num):
        if isPrime(i):
            numbers.append(i)

    return numbers

p = callIsPrime (1000)

print(int('1'*p)/p)

python

2022-09-30 18:06

1 Answers

I received a comment from @metropolis

for pin callIsPrime(1000): print(int('1'*p)%p)

resolved in .


2022-09-30 18:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.