fibo and prime series3
import math
num = int(input())
def isPrime(num):
if num == 2 or num == 3 or num == 5 or num == 7:
prime = True
elif num % 2 == 0 or num % 3 == 0 or num % 5 == 0 or num % 7 == 0:
prime = False
elif math.ceil(math.sqrt(num)) - math.floor(math.sqrt(num)) == 0:
prime = False
else:
prime = True
return prime
prime = []
for i in range(2, num * 2):
if isPrime(i):
prime.append(i)
fibo = [0, 1]
for i in range(2, (num // 2) + 1):
fibo.append(fibo[-1] + fibo[-2])
fibo.remove(0)
prime = prime[:num//2]
def merge_lists(list1, list2):
list3 = []
while True:
try:
list3.append(list1.pop(0))
list3.append(list2.pop(0))
except IndexError:
break
return list3
print(merge_lists(fibo, prime))
Are there any code examples left?
New code examples in category Python
-
Python 2023-04-11 03:04:20
-
Python 2022-03-27 22:40:04 pycharm no module named
-
Python 2022-03-27 22:25:05 assign multiple variablesin one line
-
Python 2022-03-27 22:20:02 levenshtein distance
-
Python 2022-03-27 21:35:09 get text from url python last slash
-
Python 2022-03-27 21:30:30 df concatenate df
-
Python 2022-03-27 21:25:09 python odd or even
-
Python 2022-03-27 21:15:32 python include function from another file
-
Python 2022-03-27 21:10:01 color module python
-
Python 2022-03-27 21:00:27 python tkinter cursor types