Write a Python program that takes in two positive integers (a, b) as input and prints all the prime numbers within that inclusive range.
Example 1:
Input: 2, 10
Output: 2, 3, 5, 7
Example 2:
Input: 11, 20
Output: 11, 13, 17, 19
A number is prime if it has no other divisors other than 1 and itself. You need to check this for each number in the range.
def print_primes_in_range(a, b):
for num in range(a, b + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
print_primes_in_range(2, 10)
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.