You are on page 1of 2

Python Programming I IPT102 University of Batangas

Activity and Quiz

Write a Python (or R) program that asks the user to enter an integer (X), then:

 Determines if X is prime or not


 If X is not prime, compute and print the factors of that integer X
 Evaluate and print the equation Y=8X²+ 1, for X values from -5 to 5 using the range
function and for loop

# Determines if X is prime or not


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

if X > 1:
for i in range(2, X):
if (X % i) == 0:
print(X, "is not a prime number")
print(i, "times", X//i, "is", X)
print (factors(X))
break

else:
print(X,"is a prime number")
else:
print(X,"is not a prime number")
print (X, "'s factors are: ", factors(X))

# If X is not prime, compute and print the factors of that integer X


def factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)

# Evaluate and print the equation Y=8X²+ 1, for X values from -5 to 5 using the range
function and for loop
count = 1
for x in range(-5, 5, 1):
equation = 8 * x**2 +1
print("Equation ",count, " = 8+ (", x, ")^2 +1 = ", equation)
count = count +1
Sample Output

You might also like