Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:57:18+00:00 2026-06-04T19:57:18+00:00

I am new to python and to programming all together. I am wondering if

  • 0

I am new to python and to programming all together. I am wondering if this is a terribly inefficient way of generating Fibonacci numbers for a beginner?

a = 1
b = 1
total = 0
counter = input("Please enter the term you wish to end at: ")
print "1"
print""
print "1"
number = 2

while counter > number:
    total = a+b
    print ""
    print total
    a = b
    b = total
    number = number + 1

If so, can someone point out a few things such as:

What to research/Google to make my code more efficient.

Suggest programming practices that I need to work on (I know this isn’t a huge sample of my work).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:57:21+00:00Added an answer on June 4, 2026 at 7:57 pm

    With python you do not want to worry about efficiency as much as you would in C for example, although you still want to achieve the shortest Big Oh running time. The way you have written this is around as efficient as you can get so you don’t need to worry about that too much. However, it is not very pythonic with the use of while to add to a counter.

    This can be written more simply as:

    a, b = 0, 1
    counter = input("Please enter the term you wish to end at: ")
    for _ in xrange(counter): #xrange is more efficient than range, the number is not used so _ is used to show that
        a, b = b, a+b
        print a
        print
    

    You could also use a generator for this, which might be a programming practice you could work on…

    def fib(end):
        a, b = 0, 1
        for _ in xrange(end):
            a, b = b, a+b
            yield str(a)
    
    counter = input("Please enter the term you wish to end at: ")    
    print '\n\n'.join(fib(counter))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Python and programming in general, and I was wondering if
I'm (very) new to all of this programming stuff and I need help with
first of all I'm new to python and programming but you guys already helped
I'm new to python programming. I have this problem: I have a list of
I am quite new in Python programming. While googling I found some of the
i am new to python programming.is it possible to raise exception in python without
I'm pretty new to Python programming and would appreciate some help to a problem
I am new to python (and programming in general) and am making a database/register
I'm new to python and programming in general, so would really appreciate any clarification
Ok guys, I'm really new at python (and programming itself) so sorry for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.