Jul 26, 2008

Fib Gen In Python

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Others

free web hosting

Fib Gen In Python

lloydg
OK this is one of my first programs..

from Tkinter import *
CODE
def NextNumber():
    count = 0
    x = 0
    y = 1
    while count <= int(Range.get()):
        for item in [x]:
            listbox.insert(0, item)
        z = x
        x = z + y
        y = z
        count = count + 1

root = Tk()
Title = Label(root, text = "Calculate fib number:")
Title.pack()
Range = Entry(root)
Range.pack()
PrintNextNumber = Button(root, text = "   Display   ", command = NextNumber)
PrintNextNumber.pack()
listbox = Listbox(root)
listbox.config(selectborderwidth=1, height=1, width=50)
listbox.pack()
root.mainloop()


what do you think of it???
inprovment?
comment?... do i have any bad technecs or something?.. i know i havent put any comment in the code
Notice from jlhaslip:
bbcode tags are needed on code snippets

 

 

 


Reply

MotU2510
That's pretty cool. It would be easier if you didn't use a GUI, but it's still pretty simple. Personally I'd have done something more like:
CODE
def fib_nums_1() #defining the function
    count = 0 #We set the count variable to 0 as we have not yet done any production of the numbers
    a = 0 #Sets the first variable we require
    b = 1 #Sets the second necessary variable
    print b #We print the first of our numbers
    count = count + 1 #We add one to the count variable as we have processed and printed one fibonacci number
    c = a + b #We set the second number to be printed as the sum of the first two
    print c #Now we print it
    count = count + 1 #We add another one to the count variable

def fib_nums_2() #Now we are defining the second function of our program
    a = c + b
    print a
    count = count + 1
    b = a + c
    print b
    count = count + 1
    c =  b + a
    count = count + 1

fib_nums_1()

while count != 100: #This obviously means that we will keep running the following code until the count variable is at 100, at which point we will have calculated and printed 100 fibonacci numbers
    fib_nums_2()

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : fib gen python

  1. Python - (1)
  2. Need Help With My Python Programs - just extremely basic stuff (11)
    ok, i am learning python, and i realy dont know much. my guide im using said to make a program
    where it asks your name, and if the name is yours your make it so there is a compliment, if it is
    another name you make it that its an insult, and anything else makes it say Nice name. here is what
    i wrote name = raw_input("What is your name?") if name == John: print "Your name is freaking
    sweet, you must be a god or something." elif name == Bob: print "You have a freakin' weird
    name, dude." else: print "Nice name,",name i donot understand what i am doing w...
  3. Delicious + Gmail - python (2)
    I stumbled upon this link earlier today and was hoping someone could explain or walk me through
    getting the script running. http://ponderer.org/del.icio.us I'll keep the post short since I
    have no clue as to what I should. I'll just say that I rarely work on WinXP and I would rather
    get it running on my old win box sitting in the corner. ...
  4. Python - another programming language (8)
    There are so many languages used in software and web development. Python is one of them. Basically
    Python is object-oriented , high-level programming language with dynamic semantics. Python was
    developed in the 90’s. Python is simple and easy to learn. Therefore it reduces cost of program
    maintenance. It is very attractive for rapid application development because of its high-level
    built-in data structures, combined with dynamic typing and dynamic binding. Python is also use as a
    scripting or glue language to connect existing components. Python supports modules and ...
  5. [pygame] Python Game - (4)
    On this tutorial we will see how to draw a circle on the screen and move it around using the arrows
    of the keyboard. (Don't worry if you don't get anything, the code will be analysed line by
    line) CODE #!/usr/bin/env python import pygame from pygame.locals import * if not
    pygame.font:     print 'Atention, there are no fonts.' if not pygame.mixer:
        print 'Atention, there is no sound.' pygame.init() red = (255, 0,
    0) black = (0, 0, 0) window_width = 640 window_height = 480 window = pygame...
  6. Python Manace: Control Flow I - python tutorial (3)
    Hello This is the first part of my Python tutorial. The code is pretty self-explanatory so few
    comments should be enough. If not - let me know. Tutorial assumes that You have already Python
    installed. Python 2.4 should be enough. Let's go, then. #! /usr/bin/env python # -*-
    coding: utf-8 -*- import math def squareRoot_1( lst ) : """Returns list of square
    roots. No negative number validation. Allows fractions in result.
    """ result = for el in lst : sqrtFloat = math.sqrt( el ) ...
  7. Python - Programming Language (4)
    Does anybody else know any python? I've started learning it, because I heard somewhere that it
    is quite easy to learn and I want to learn a programming language quickly /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. I haven't learned how
    to do any complex stuff with it yet, but its still fun learning about it /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. If you want to find out
    more info about Python, then you can go to their website. I'm not sure if i'm allowed to
    post links...
  8. Password Generator - Made in Python (9)
    This is a Password Genorator i made in python use Tkinter as the GUI. I will Compile it soon so
    people with out Python can use it. here is the source code CODE import random, math from
    Tkinter import * root=Tk() root.title("PassGen") length = Label(root,
    text="password length:") length.pack() input = Entry(root,
    text="8") input.pack() input.insert(0, "8") units =
    "abcdefghijkmnopqrstuvwxyz0123456789" password = Label(root,
    text="password:") pas...
  9. Ok, So I'm Learning Python... - (3)
    I was wondering, can I make games in python, even simple text based ones? me and my friend wanted to
    start making homebrew games, and we decided to start out learning python. I've learned a bit,
    not much, but enought to make one of those conversations with the computer, like with loops and
    where they ask questions like "what is your name?" and then say it back etc. We plan on also
    learning C++, which we will learn later after we get real good with Python. However, will I
    eventually be able to make games with Python?...



Looking for fib, gen, python

Searching Video's for fib, gen, python
advertisement



Fib Gen In Python



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE