Question

Problem 1 Every line in the file grades.txt has the following structure: name homework scores quiz scores test scores The sco
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution to Problem 1 is given below along with documentation:

------------------------------------------------------------------------CODE-------------------------------------------------

def transform():
   D={}
   file=open('grades.txt')
   for i in file:
       L=i.split("|")
       name=L[0]
       '''
           By using map() function we can map the values
           present in the List to a function
           let the line be
           'Scott|100.0 100.0 90.0|92.0 88.0 77.0|98.0 92.0 100.0'
           so now
           L=['Scott','100.0 100.0 90.0','92.0 88.0 77.0','98.0 92.0 100.0']
           now using map() we can convert the string literals into floating point literals
       '''
       homework_scores=list(map(float,L[1].split()))
       quiz_scores=list(map(float,L[2].split()))
       test_scores=list(map(float,L[3].split()))
       temp_dict={ 'Homework':homework_scores,\
                   'Quiz':quiz_scores,\
                   'Test':test_scores }
       D[name]=temp_dict
   return D

#the following print() is to test the function
print(transform())

--------------------------------------------------------END-------------------------------------------------------------------

Code in sublime text:

/grades.py - Sublime Text (UNREGISTERED) Edit Selection Find View File Tools Project Preferences Help Goto grades.py cons.py

OUTPUT:

gm@localhost: Terminal Help Search File Edit View gm@localhost:~$ cat grades.txt Scott|100.0 100.0 90.0|92.0 88.0 77.0|98.0 9

Solution for the Problem 2:

--------------------------------------------------------------------------CODE-----------------------------------------------

def student_average(name):
   details=transform()
   student_grades=details[name]
   L=student_grades['Homework']
   hs=sum(L)/len(L)*0.2
   L=student_grades['Quiz']
   qs=sum(L)/len(L)*0.3
   L=student_grades['Test']
   ts=sum(L)/len(L)*0.5
   avg=hs+qs+ts
   return round(avg,2)

#the below print() is for testing
print(student_average('Scott'))

---------------------------------------------------------------END----------------------------------------------------------

Code in sublime text:

/grades.py - Sublime Text (UNREGISTERED) Find View File Edit Selection Tools Project Preferences Help Goto grades.py cons.py

OUTPUT:
gm@localhost: Terminal Help File Edit Search View gm@localhost:~$ python grades.py 93.37 gm@localhost:~$

Have a nice Day...............:D

Add a comment
Know the answer?
Add Answer to:
Problem 1 Every line in the file grades.txt has the following structure: name homework scores quiz...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I wrote a program that takes a person's name and their 10 quiz scores from an...

    I wrote a program that takes a person's name and their 10 quiz scores from an input file and then prints it to an output file in a slightly different format that also has the average of their quiz scores. Here is an example INPUT Mike Johnson 100 45 68 99 34 66 88 99 88 66 OUTPUT Student Name Quiz Scores Average Johnson, Mike 100 45 68 99 34 66 88 99 88 66 75.30 It works fine when...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

  • C++ Homework Help: The text file that it wants you to download is this: Name: Peter...

    C++ Homework Help: The text file that it wants you to download is this: Name: Peter Parker CSCI-261: 95 CSCI-262: 90.625 CSCI-442: 91.20 Name: Mary Smith CSCI-442: 65.0 CSCI-562: 79.1234 CSCI-580: 70.24 Name: Pat Brown CSCI-562: 95 CSCI-565: 88.0 CSCI-580: 91.20 Name: Linda Williams CSCI-262: 65.0 CSCI-306: 67.719 CSCI-562: 70.200 Name: John Miller CSCI-261: 95.281 CSCI-306: 90.625 CSCI-565: 91.20 Name: Patricia Johnson CSCI-306: 65.012 CSCI-442: 84.76 CSCI-580: 70 Name: Brian Hall CSCI-261: 65.0 CSCI-306: 84.712 CSCI-442: 75.24 Name: Sandra Nelson...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT