163k views
3 votes
Assume a function called isprime() is available for you to use in a module called ENGR102. The input parameter for isprime() is a single integer and the return value is a Boolean that depends on if the input is a prime number (True) or not (False). Write a Python program that allows the user to input two integers and then tests all of the odd numbers between and including these two numbers to see if they are prime numbers or not using the isprime() function (you should not test even numbers, and you should cycle through all tests using a loop structure). The result of your program should be a printed list of prime numbers found. If no prime numbers were found, then your program should print that no prime numbers were found. Start your code with: from ENGR102 import isprime

User Alpesh
by
7.5k points

1 Answer

4 votes

Final answer:

This Python program allows the user to input two integers, and then tests all of the odd numbers between and including these two numbers to see if they are prime numbers or not using the isprime() function. The result is a printed list of prime numbers found.

Step-by-step explanation:

In this Python program, we are given a function called isprime() from the ENGR102 module, which checks whether a given number is prime or not.

To solve this problem, we need to take input from the user for two integers, and then use a loop to iterate through all the odd numbers between and including these two numbers.

For each odd number, we will call the isprime() function to check if it is prime or not. The prime numbers found will be stored in a list.

Here is the code:

from ENGR102 import isprime

start = int(input('Enter the starting number: '))
end = int(input('Enter the ending number: '))

prime_numbers = []

for i in range(start, end+1):
if i % 2 != 0 and isprime(i):
prime_numbers.append(i)

if prime_numbers:
print('Prime numbers found:', prime_numbers)
else:
print('No prime numbers found.')
User SabareeshSS
by
8.5k points