Prime & Fibonacci Numbers in Python | Print the First n Prime & Fibonacci Numbers in Python

preview_player
Показать описание
A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number.

The Fibonacci numbers, commonly denoted F(n), form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, and for n greater than 1.

Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace.

Рекомендации по теме
Комментарии
Автор

prime function and fibonacci function are not efficiently:
ignore even number can help your prime function goes 1/2 time. check from 3 to square(i) even faster
your fibonacci needs to call back 2 previous fList, then also other fList.

for prime:
from math import sqrt
def prime(i):
if i < 2: return False
elif i == 2 or i == 3: return True
elif i % 2 == 0: return False
for d in range(3, int(sqrt(i))+1, 2):
if i % d == 0: return False
return True

for Fibonacci:
n = int(input())
a, b = 1, 1
f = [1, 1]
while len(f) < n:
a, b = b, a + b
f.append(b)

Hellangelx
visit shbcf.ru