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

Asrarahmed Kadri 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
    else:
       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


HTH,

Regards,
Asrarahmed Kadri

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
> schoolproject.
>
> 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
> it.
>    fout = open("draw__output.dat", "a")
>    fout.write(output_string)   #writing string to file
>    fout.close()
>    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.
>
> thanks,
>
> Robert (forgive me my english, I am Dutch)
>
> _________________________________________________________________
> Windows Live Mail: Kies je eigen kleur, indeling en contacten!
> http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061126/bd720ffd/attachment.htm 


More information about the Tutor mailing list