[Tutor] First Try 1.2

John Connors oztriking at hotmail.com
Tue Feb 21 12:02:50 CET 2006


G'day :)

I've added a little more to the program. It now sorts the game numbers from 
lowest to highest which makes filling out the tickets a lot easier, I've 
been putting off doing this because I wasn't sure how to go about it but 
once I started looking I found python does it all for me with .sort()

Also added some extra user input so different types of lotto games can be 
played.

Found a glaring bug...the program didn't pick the winning numbers for me and 
I'm now $6 poorer!!!!! <g>

Next on the to do list is add an option for a power ball, I actually did 
this tonight but I had 'if' statements all over the place. Which made the 
code unreadable so I'm going to work on a different way of doing it.

I hope posting my efforts in here is ok. I learnt a lot after posting the 
first version of it but if I'm doing the wrong thing please tell me and I'll 
desist.


import random

# create or replace lotto.txt in my home directory
file('/home/mutt/lotto.txt','w').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? '))

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
    lotto_numbers = random.sample(xrange(1,number_of_balls + 1), 
how_many_numbers)
    lotto_numbers.sort()

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

    # append the numbers to lotto.txt
    file('/home/mutt/lotto.txt','a').write('Game: ')
    file('/home/mutt/lotto.txt','a').write(str(game))
    file('/home/mutt/lotto.txt','a').write('    ')
    file('/home/mutt/lotto.txt','a').write(str(lotto_numbers))
    file('/home/mutt/lotto.txt','a').write('\n')

print '\nHope you win!'
file('/home/mutt/lotto.txt','a').write('\n\nHope you win!')


John

_________________________________________________________________
Search for local singles online @ Lavalife - Click here  
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D21550&_t=21550&_r=endtext&_m=EXT



More information about the Tutor mailing list