start = int(input("Enter the start of the range: "))
end = int(input("Enter the end of the range: "))
for num in range(start, end + 1):
if num > 1 and all(num % i != 0 for i in range(2, num)):
print(num)
Explanation:
Input the Range
start = int(input("Enter the start of the range: "))
end = int(input("Enter the end of the range: "))
input(): Prompts the user to enter the start and end values of the range.
int(): Converts the inputs into integers.
start and end define the range of numbers to check for primality.
Loop Through the Range
for num in range(start, end + 1):
range(start, end + 1): Generates all numbers from start to end, inclusive of end.
The variable num iterates through each number in this range.
Check if the Number is Prime
if num > 1 and all(num % i != 0 for i in range(2, num)):
num > 1: Ensures the number is greater than 1.
Print the Prime Number
print(num)
If the if condition is satisfied (the number is prime), it prints the number.
#source code --> clcoding.com
0 Comments:
Post a Comment