[Tutor] Newbie string & File I/O questions.....
ajkadri at googlemail.com
Sun Nov 26 21:05:35 CET 2006
You can use, '\n' with each value, that u are writing to the file.
eg. outstring = outstring + '\n'
\n stands for new line character.
I couldnt get the second question.
Regarding the third question, you can do this:
done = 0
fd = open(filename,'r')
while not done:
line = fd.readline()
if line == '':
done = 1
for i in line:
dict[i] = int(dict[i]) + 1 # dict is a dictionary containing
numbers as the keys and initial value 0 for each key
On 11/26/06, Moedeloos Overste <kloosterjunkie at hotmail.com> wrote:
> 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
> should see (if he wants to) how many times each of the possible numbers
> picked by the computer and which were the six most succesful numbers.
> 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
> # 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
> 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
> 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!
> Tutor maillist - Tutor at python.org
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor