[Tutor] Newbie string & File I/O questions......

Moedeloos Overste kloosterjunkie at hotmail.com
Sun Nov 26 20:42:59 CET 2006

Hi everybody,

I am new to python and trying to write a lottery program for a 

The program is supposed to draw the lottery any entered(user input) number 
of times, then store the drawing results in a file. After drawings the user 
should see (if he wants to) how many times each of the possible numbers was 
picked by the computer and which were the six most succesful numbers. These 
data must be calculated from the data stored in the file!

This is what I've been able to come up with so far:

# Lottery chances.
# Programs ask how many times you want to have the lottery drawn by the
# computer. Then stores these draws and then shows the 6 numbers most drawn
# by the computer.

# Importing for making the program nicer later on...
import os, sys
import time
import random

vDraws = input("How many times do you want to draw the lottery? :>")

# Draw lottery numbers & writing them to file

while vDraws > 0:
    List_LotNumbers = random.sample(range(0,46), 6) #random numbers from 
range into list
    output_string = str(List_LotNumbers) #converting list to string to store 
    fout = open("draw__output.dat", "a")
    fout.write(output_string)   #writing string to file
    vDraws = vDraws - 1

# Printing all numbers drawn

vView = raw_input("Do want to see the results? y/n :>")

if vView == "y" or vView == "Y":
    fout = open("draw__output.dat", "r")
    Print_list = fout.readline()
    print Print_list

#end of program so far

My question is: how do I write the output of each lottery drawing on a 
separate line

second question: how do i print the lottery drawings to the screen without 
the brackets[]

third:can somebody point me in the right direction as to how do I make the 
program read from the file and count how many times a number has been drawn.

Any help or pointers would greatly be appreciated.


Robert (forgive me my english, I am Dutch)

Windows Live Mail: Kies je eigen kleur, indeling en contacten! 

More information about the Tutor mailing list