[Tutor] Simple address book program in python

Fred Gerbig fgerbig@usd253.org
Wed, 13 Feb 2002 12:44:34 -0600


Hello all,

This is my first message. I am just starting out with python, I have done
some VB and C in the past. When I started playing with BASIC years ago I
wrote a little address book program to learn how to program. I would like to
do the same type of thing in Python.

Just something simple that would prompt the user for the different fields..
first name, last name, address etc, then store the info in a text file. Then
have some sort of search that would prompt the user for the last name for
example and then go out search the text file, find the record and display it
(using a simple sequential file).

I am sure someone has to have done something similar in the past. If I can
get a look at some code that does something like I want to do it will be a
big step ahead in the learning process.

Thanks!!
---
Fred Gerbig

Here is my first project that I have done in Python:
---------------------------------------------------
#A program to simplify a fraction and convert it to decimal and a percent

num = input("Enter the numerator: ")
den = input("Enter the denominator: ")
test = 0 #A simple test condition to break out of the loop.

if num > den: #Check to see if an improper fraction was entered.
    whole = num/den #Do the math
    rem = num%den

    if rem != 0: #If there is no remainder goto else.
        for i in range(1000,0,-1):
            if num%i == 0 and den%i == 0 and test != 1: #Find the Greatest
Common Factor.
                a = rem/i
                b = den/i
                test = 1 #Break out of the loop.
                print "You entered an improper fraction, simplified it is:
%d %d/%d" % (whole,a,b)
                c = float(a)/float(b)
                print "The fraction you entered converted to decimal is:
%.4f." % (whole+c)
                print "The fraction you entered converted to percent is:
%d%%." % ((whole+c)*100),

    else: #Go here if the improper fraction simplifies to a whole number.
        print "You entered a improper fraction, simplified it is: %d" %
(whole)

else: #If a proper fraction is entered start here.
    for i in range(1000,0,-1):
        if num%i == 0 and den%i ==0 and test != 1:
            a = num/i
            b = den/i
            test = 1
            print "The fraction you entered is %d/%d in lowest terms." %
(a,b)
            c = float(a)/float(b)
            print "The fraction you entered converted to decimal is %.4f." %
(c)
            print "The fraction you entered converted to percent is: %d%%."
% (c*100),