+ 1
I am not getting the output for this function
Fill in the blanks to create a prime number generator, that yields all prime numbers in a loop. (Consider having an is_prime function already defined): def get_primes(): num = 2 while True: if is_prime(num): yield num num += 1 ##The output i am getting is NO OUTPUT......I am not getting the prime numbers
6 Respostas
+ 4
you need to indent the while loop
def get_primes():
num=2
while True:
if is_prime(num):
yield num
num+=1
+ 1
def get_primes():
num=2
while True:
if is_prime(num):
yield num
num+=1
0
You need to print using print function
0
here is my code
def fibonacci(n):
if n == 1 or n == 2
return 1
return fibonacci(n-1) + fibonacci(n-2)
for i in range (1, 11):
print(fibonacci(i))
0
num= int(input())
def fibonacci(n):
if n <= 1:
return n;
return fibonacci(n-1) + fibonacci(n-2)
for i in range(num):
print(fibonacci(i))
0
question : Fill in the blanks to create a prime number generator, that yields all prime numbers in a loop.
(Consider having an is_prime function already defined):
program : def get_primes():
num = 2
while true:
if is_prime(num):
yield num
num+=1