[Tutor] First Try

John Connors oztriking at hotmail.com
Sun Feb 19 11:33:37 CET 2006


G'day :)

I started getting sick of reading tutorials so for a bit of a break I set 
myself the task of writing a program to pick lotto numbers, 6 numbers 
between 1 and 44 (inclusive). I had done this many years before in basic and 
I thought back then it would be a simple task but I struck a problem of the 
random number generator repeating numbers occasionally so I had to check 
each number against the other and generate another random number if there 
were duplicates.

So I was prepared for the same problem with python but I found that python 
takes care of that for me so the program would only have to be one line. I 
decided to make it a little more user friendly and allow the user to pick 
home many games they want generated. Then I made the output a little easier 
to read with a few blank lines. Here is what I came up with:


import random

numberof = int(raw_input('Enter how many games you would like generated :')) 
#user input for number of games to choose

print
print
print "Here are your numbers :"
print

for games in range(1, numberof + 1): #loop for the number of games selected 
by user
    lotto = random.sample(xrange(1,45), 6) #generate 6 random numbers 
between 1 and 44 inclusive
    print games, lotto
    print

else:
    print
    print "Hope you win!"


I know this is a very simple program but... could I have done this a better 
way?

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