Doubt about python/basic algorithms

Asked

Viewed 46 times

-2

I am making a personal challenge,develop the smallest program possible to manage a fibonati sequence and that shows the fi(gold number).

Most recent code :

nf = int(input("Quantos numeros da sequencia de fibonati voce quer ?"))
t = 0
tt = 1
ttt = 1
tf = 0


def fibo(a, b, c, d):
    d = a
    c = b + a
    print("{} - ".format(a),end='')
    a = b
    b = c
    return a, b, c, d


for i in range(nf):
    t,tt,ttt,tf = fibo(t, tt, ttt, tf)
print(tf,".")
print(tt / t)

The problem arises when I try to finilizar,a wanted the sequence to termisse with a ".". As I noticed in the code I tried to use a room in the office,.

I don’t know how I can do, >.</

  • https://ideone.com/5Hfamy

1 answer

-1

I managed to do what I want, =)

nf = int(input("Quantos numeros da sequencia de fibonati voce quer ?"))
t = 0
tt = 1
ttt = 1
print("{} - ".format(t),end="")


def fibo(a, b, c):
    c = b + a
    print("{} - ".format(b),end='')
    a = b
    b = c
    return a, b, c,


for i in range(nf - 2):
    t,tt,ttt = fibo(t, tt, ttt)
print(ttt,".")
print(tt / t)
  • If you’re only concerned about the number of lines, don’t create a function: https://ideone.com/tgqUdq - you want even fewer lines: https://ideone.com/BOT19x (although I don’t recommend this, as the code gets more confusing and difficult to read - after all, fewer lines aren’t necessarily better)

  • I did it, it got 9 lines that remind me

  • 'I don’t know why I was trying to make a function for fiberKEWKEKKE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.