[Tutor] First Try 1.2

John Connors oztriking at hotmail.com
Wed Feb 22 09:57:30 CET 2006


G'day,

Added a power ball option to the lotto program today. The program does way 
more then I ever intended when I started it so I'll try a new project. Maybe 
I'll come back to it when I try out Tkinter and try to give it a GUI.

Anyway....here's my latest effort.


import random

# store the /home/mutt/lotto.txt in f
f = file('/home/mutt/lotto.txt','w')
# create or replace lotto.txt in my home directory
f.write('Here are your numbers:\n\n')

# user input for number of games to generate
how_many_games = int(raw_input('How many games you would like generated? '))
# user input for number of balls (to allow different lotto games)
number_of_balls = int(raw_input('\nHow many balls are in the lotto you wish 
to play? '))
# user input for how many numbers per game (to allow systems entries)
how_many_numbers = int(raw_input('\nHow many numbers you would like per 
game? '))
# check if there is a power ball
chk_pwrball = raw_input('Is there a power ball? (y/n) ')

print '\n\nHere are your numbers : \n'

# loop for the number of games selected by user
for game in range(1, how_many_games + 1):

    # generate 6 random numbers between 1 and 45 inclusive then sort them
    lotto_numbers = random.sample(range(1,number_of_balls + 1), 
how_many_numbers)
    lotto_numbers.sort()

    if chk_pwrball == 'n':

        # Right justified in 3 character width then a tab (\t) then a blank 
line (\n)
        print '%3s\t%s\n' % (game, lotto_numbers)

        # write the numbers to lotto.txt
        save_numbers = 'Game: %3s\t%3s\n' % (game, lotto_numbers)
        f.write(save_numbers)

    if chk_pwrball == 'y':
        pwrball = random.sample(range(1,number_of_balls +1), 1)
        print '%3s\t%s   \tPower Ball: %s\n' % (game, lotto_numbers, 
pwrball)
        save_numbers = 'Game: %3s\t%s   \tPower Ball: %s\n' % (game, 
lotto_numbers, pwrball)
        f.write(save_numbers)

print '\nHope you win!'
f.write('\nHope you win!')
f.close()



John

_________________________________________________________________
Shopping made easy @ tradingpost.com.au 
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fwww%2Etradingpost%2Ecom%2Eau%2F%3Freferrer%3DnmsnHMetagv1&_t=753082530&_r=emailtagline&_m=EXT



More information about the Tutor mailing list