The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
A little project help..
Discuss A little project help.. in the Python Programming forum on Dev Shed. A little project help.. Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 6th, 2012, 10:07 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 55 m 58 sec
Reputation Power: 0
|
|
|
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:
David
102
Hector
300
Mary
195
Jane
160
Sam
210
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.).
And,
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".
|

December 6th, 2012, 11:31 AM
|
 |
Contributing User
|
|
|
|
__________________
[code] Code tags[/code] are essential for python code!
|

December 6th, 2012, 11:39 AM
|
 |
Contributing User
|
|
Join Date: May 2012
Location: 39N 104.28W
Posts: 97
Time spent in forums: 1 Day 15 h 26 m
Reputation Power: 2
|
|
|
Let's look at the first problem.
To read a text file, you have to open it:
fid1=open("bowlingscores.txt","r")
To write a text file, you have to open that, too:
fid2=open("bowlingaverages.txt","w")
It seems to me that you're going to want a list of the names and scores so I would initialize that:
lst1=[]
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:
<indent>lst1.append(strLing.strip('\n'))
Now just for jollies, it's good practice to close the input file:
fid1.close()
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:
dct1={}
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:
lsta=strLine.strip('\n').split()
dct1[lsta[1]=lsta[2]
again, see if that gets you started.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|