There are a few issues with the code:

  1. The loop condition for i in range(2,y) should be for i in range(2, y+1) to include the square root value in the iteration.

  2. The check if x%i != 0 should be if x % i == 0. If the remainder is 0, it means the number is divisible by i and hence not prime.

  3. The line i += 9999999999999999999999 is unnecessary and incorrect. It doesn't serve any purpose in determining whether the number is prime or not.

  4. The final condition if i < 9999999999999999999999 is not needed. Instead, you can use an else statement to print that the number is prime.

Here's the modified code:

import math
x = int(input('enter the number'))
y = int(math.sqrt(x))
is_prime = True
for i in range(2, y+1):
    if x % i == 0:
        is_prime = False
        break
if is_prime:
    print('The number is prime')
else:
    print('The number is not prime')

This code checks if the number is divisible by any number from 2 to the square root of the given number. If it is divisible by any of these numbers, it is not prime. Otherwise, it is prime

import mathx = intinputenter the numbery = intmathsqrtxi = 2for i in range2y if xi != 0 printthe number is not a prime i += 9999999999999999999999 else i += 1if i 999999999

原文地址: http://www.cveoy.top/t/topic/iNqX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录