Separate print from two Python structures

Asked

Viewed 137 times

-1

I made a small program in Python that asks the user to type any integer number, right after it shows the Fibonacci sequence (number of times) and then shows the number of even numbers until that determined number that the user typed.

aa = 0
a = 1

fim = int(input('Digite um termo: '))

for n in range (0,fim):
    s = (aa + a)
    print(s, end = ' → ')
    aa = a
    a = s

s = 0
while s <= fim:
     if s % 2 == 0:
         print(s, end=' → ')
     s = s + 1

My problem is this, I wanted the result to input=10 (example) were so

>>> %Run q1.py
Digite um termo: 10
1 → 2 → 3 → 5 → 8 → 13 → 21 → 34 → 55 → 89
→ 0 → 2 → 4 → 6 → 8 → 10 →

But the program put it all together:

>>> %Run q1.py
Digite um termo: 10
1 → 2 → 3 → 5 → 8 → 13 → 21 → 34 → 55 → 89 → 0 → 2 → 4 → 6 → 8 → 10 → 

How do I separate these prints in two lines? one for Fibonacci and the other for pair counting.

1 answer

1


aa = 0
a = 1
fim = int(input('Digite um termo: '))
for n in range (0, fim):
    s = (aa + a)
    print(s, end = ' → ')
    aa = a
    a = s
print()
s = 0
while s <= fim:
     if s % 2 == 0:
         print(s, end=' → ')
     s = s + 1

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

I just said skip a line on the spot you want.

Better variable names would help understanding.

  • That’s right, I’ll never forget it, thank you!!

Browser other questions tagged

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