Python Forum
[split] help a brother am so new
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] help a brother am so new
#3
That is, well, kinda screwed up. Sorry. Here:
fibLimit= int(input('Enter how many Fibonacci numbers you would like to print = '))
fbNext = [0,1]
 
for i in range(fibLimit):
    if i<2 :
        print(fbNext[i])
    else:
        fbNext.append(fbNext[i-2] + fbNext[i - 1])
        print(fbNext[i])
fibLimit should be int() rather than eval()
fbNext can be initialized as [0,1]
Any time you see range(len(xxx)) re-evaluate. That is almost always wrong. You want the range of fibLimit, not anything to do with fbNext.
I wrote it so you append to the fbNext list as that seemed to be your preference, fixed the syntax and code.
Reply


Messages In This Thread
[split] help a brother am so new - by MohsinCoding - Feb-13-2020, 12:42 PM
RE: [split] help a brother am so new - by Larz60+ - Feb-13-2020, 06:09 PM
RE: [split] help a brother am so new - by jefsummers - Feb-14-2020, 12:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help a brother am so new manimani 5 2,407 Feb-14-2020, 11:22 PM
Last Post: michael1789

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020