1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Rep Power

    A little project help..

    I'm really new to programming & I'm taking an entry level course right now.My professor gave us 2 projects here (below). Does anyone think they could find the time to help me out with these projects? I'm so confused & these are our last two projects and he won't be on campus anymore. I'm not asking anyone to do them for me, but guidance would help me a lot. Please & Thank you in advance.

    1.)Write a program that will read an unknown number of bowlers and their bowling scores (with possible values from 1 to 300) from an external file called "bowlingscores.txt". The file will look similar to the following:

    Output the bowlers’ names to an external data file called "bowlingaverages.txt". Next to each bowler's name, print a message dependent on their scores:
    For perfect scores (equal to 300), output “perfect”
    For those scores greater than the average score, output “above average”
    For those below average, output “below average”
    Your program must include at least one function (e.g., to calculate the average, to determine the appropriate message to print, etc.).


    2.)Your program needs to decode an encrypted text file called "encrypted.txt". The person who wrote it used a cipher specified in "key.txt". This key file would look similar to the following:

    A B
    B C
    C D
    D E
    E F
    F G
    G H
    H I
    I J
    J K
    K L
    L M
    M N
    N O
    O P
    P Q
    Q R
    R S
    S T
    T U
    U V
    V W
    W X
    X Y
    Y Z
    Z A

    The left column represents the plaintext letter, and the right column represents the corresponding ciphertext.

    Your program should decode the "encrypted.txt" file using "key.txt" and write the plaintext to "decrypted.txt".
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    We covered this assignment a while ago. It's too much information---please write your own code.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    39N 104.28W
    Rep Power
    Let's look at the first problem.
    To read a text file, you have to open it:

    To write a text file, you have to open that, too:

    It seems to me that you're going to want a list of the names and scores so I would initialize that:

    Normally (and in this case, too), you step through a file using the iterator quality of the file object:
    for strLine in fid1:

    Now, in your case, each line is just one thing so, after stripping off the linefeeds, you would append it to the list:

    Now just for jollies, it's good practice to close the input file:

    Now lst1 has names and numbers (as strings) in succession. I would make those into a list of tuples (using list comprehension), each tuple being a (name, number) pair:
    lst2=zip([i for i in lst1[::2]],[i for i in lst1[1::2]])

    now each element of lst2 looks like: ("David","102)

    Let's see if that gets you started on that one.

    For the second one, I'd use a dictionary (actually, this is the very definition of a case for a dictionary). So just like before, you'd open the file. This time you initialize a dictionary:

    Now, after reading each line and stripping the linefeeds, you want to add a dictionary entry like {'B':'A'} in the case of the first one. That is "if I read "B", that means "A". So now, as you read each strLine:

    again, see if that gets you started.

IMN logo majestic logo threadwatch logo seochat tools logo