[Tutor] PYTHON NEWBIE HELP!

bob gailer bgailer at gmail.com
Mon Oct 15 04:42:26 CEST 2012


On 10/14/2012 9:21 PM, Salinas, Erwin d wrote:
> HELP! Hi I'm a newbie in Python,
welcome

A few pointers regarding use of this email list:
- we are a few volunteers who try to help as we can
- please put your responses following the relevant text rather than at 
the top
- please reply-all so a copy goes to the list.
- please submit plain text rather than formatting or colors.
- tell us what os and python version you are using
- remove extraneous text
- provide a meaningful subject
- regarding homework

> I'm having trouble organizing the FILE into the OUTPUT BELOW. I put 
> the file into read, then I put it on a list, and my plan is to put the 
> name and the corresponding grades into a dictionary, using the 
> elements on the list, but when I print the dictionary, it's not giving 
> me the result I wanted. MY CODE SO FAR IS SHOWN BELOW THE 
> OUTPUT. For more details of the assignment, go to this 
> link<http://ranger.uta.edu/%7Ekamangar/Courses/CSE_1310_FA12/Homework5%28DueDate.Oct.16,2012%29.html#Topic18> 
> http://ranger.uta.edu/~kamangar/Courses/CSE_1310_FA12/Homework5(DueDate.Oct.16,2012).html#Topic18. 
> Thank you so much.
>
> FILE
> HM3, 80 , HM2 ,90 , ID, 1000123456,HM4,92,Last_name,Rubble
> ID, 1000100200,Last_name,Bunny,HM2,92,HM5,70,HM1,98,
> ID, 1000123300,HM1,86, HM3,100,Last_name,Duck
> HM4,96,Last_name,Chipmunk,HM1,86,ID,1000456456
> Last_name,Simpson,HM3,70, HM1, 90 ,ID, 1000321321,Test1,90
> HM1,87,Last_name,Duck,HM2, 100 ,HM4,94,ID, 1000123300
> HM3,95,HM2,88,Last_name, Chipmunk ,HM1,86 , ID,1000999888
> HM1, 92 ,Last_name,Simpson,ID, 1000321321,HM2,90
> OUTPUT
> Name | ID | HM1 | HM2 | HM3 | HM4 | Avg. |
> ___________________________________________________________________
> Bunny | 1000100200 | 98 | 92 | 0 | 0 | 47.50 |
> Chipmunk | 1000456456 | 86 | 0 | 0 | 96 | 45.50 |
> Chipmunk | 1000999888 | 86 | 88 | 95 | 0 | 67.25 |
> Duck | 1000123300 | 87 | 100 | 100 | 94 | 95.25 |
> Rubble | 1000123456 | 0 | 90 | 80 | 92 | 65.50 |
> Simpson | 1000321321 | 92 | 90 | 70 | 0 | 63.00 |
> THIS IS MY CODE SO FAR
> filename = open("student_grades_hm_5.txt")
> infile = filename.read()
> mix_list = infile.split()
> print "Name | ID | HM1 | HM2 | HM3 | HM4 | Avg. |"
> print "______________________________________________________"
>
> Student_one = 
> {"Name":mix_list[9],"ID":mix_list[5],"HM1":0,"HM2":mix_list[3],
> "HM3":mix_list[1],"HM4":mix_list[7]}
> print Student_one
You seem to be missing a number of basic concepts. It is hard to tell 
how much help is allowed by your instructor.

Did you successfully complete the preceding assignments? Since the 
"purpose" is to use lists, file i/o, loops and formatted print I assume 
you already know how to use split and dictionaries. True?

What elements of the "purpose" are giving you trouble? Since I see no 
loop or formatted print I assume these are giving you grief.

I suggest you start with a bit of pseudo-code to express the structure 
of the program.

Your program should not refer to the keys explicitly as you have done in 
the line starting with Student_one = nor should it refer to the list 
elements by number (that implies knowledge of the structure of a 
particular line of the file.

I also suggest you examine the results of each step by entering the 
lines at the interactive prompt, then displaying the value of the newly 
created variable. You will be surprised by what you see!

My personal guess is that you have not done the prior exercises or else 
the instructor is expecting miracles.

Do what you can to improve things then return with more questions.

-- Bob Gailer
919-636-4239
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121014/c1393f80/attachment-0001.html>


More information about the Tutor mailing list