“Fibonacci Generador de secuencia Python” Código de respuesta

generador de fibonacci

def fib(num):
    a = 0
    b = 1
    for i in range(num):
        yield a
        a, b = b, a + b # Adds values together then swaps them

for x in fib(100):
    print(x)
Tronald

Fibonacci Generador de secuencia Python

#Learnprogramo
Number = int(input("How many terms? "))
# first two terms
First_Value, Second_Value = 0, 1
i = 0
if Number <= 0:
print("Please enter a positive integer")
elif Number == 1:
print("Fibonacci sequence upto",Number,":")
print(First_Value)
else:
print("Fibonacci sequence:")
while i < Number:
print(First_Value)
Next = First_Value + Second_Value
# update values
First_Value = Second_Value
Second_Value = Next
i += 1
Gleaming Grasshopper

Secuencia de fibonacci pitón

startNumber = int(raw_input("Enter the start number here "))
endNumber = int(raw_input("Enter the end number here "))

def fib(n):
    if n < 2:
        return n
    return fib(n-2) + fib(n-1)

print map(fib, range(startNumber, endNumber))
lostDev

Respuestas similares a “Fibonacci Generador de secuencia Python”

Preguntas similares a “Fibonacci Generador de secuencia Python”

Más respuestas relacionadas con “Fibonacci Generador de secuencia Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código