0% found this document useful (0 votes)
3 views2 pages

Python Program Solution

The document contains two Python functions: one to check if a number is prime by counting its factors and another to evaluate and print the equation y = 8x^2 + 1 for x values ranging from -5 to 5. The prime-checking function outputs whether the number is prime and lists its factors. The equation evaluation prints the corresponding y values for each x in the specified range.

Uploaded by

Merengo Brian
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Program Solution

The document contains two Python functions: one to check if a number is prime by counting its factors and another to evaluate and print the equation y = 8x^2 + 1 for x values ranging from -5 to 5. The prime-checking function outputs whether the number is prime and lists its factors. The equation evaluation prints the corresponding y values for each x in the specified range.

Uploaded by

Merengo Brian
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

CHECKING PRIME NUMBER


#function to check whether the number is prime or not

def check_prime(x ) :

#creating an empty list to store factors of x

factors =[]

#declaring variable count starting with zero

count=0

#iterate from 1 to x

for i in range (1,x+1):

#check if x value is divisible by i

if x%i ==0:

#increment count value by 1

count=count+1

#adding i value to list factors

[Link](i)

#compare whether count value is equal to 2

if count==2:

#if count value is equal to 2 then x is a prime number

print(x, "is a prime number")

else:

#if count value is not equal to 2 then x is not a prime number

print(x, "is not a prime number")

print("factors of " ,x, "is:", *factors )

#asking the user too enter the integer x

x=int(input("Enter an integer (X):"))

#calling the function check_prime and printing results

check_prime(x)
2. EVALUATING AND PRINTING AN EQUATION

#iterate x value from -5 to 5


for x in range(-5,6):
#print equation y
print("When x =", x, "then y=", 8*pow(x,2)+1)

You might also like