Can anyone give me these solution PLZ.

import string

STUDENT_ID = 0
STUDENT_FIRST_NAME = 1
STUDENT_SECOND_NAME = 2
STUDENT_MARK = 3

def inputMarks (mList):

    print "inputMarks not yet implemented"

def calcGrade (mark):

    print "calcGrade not yet implemented"
    
def printIndividualRecord (record):

    print "printIndividualRecord not yet implemented"
    
def printAllRecords (mList):

    print "printAllRecords not yet implemented"
    

def swap (pos1, pos2, mList):
    temp = mList[pos1]
    mList[pos1] = mList[pos2]
    mList[pos2] = temp

 
def maxListByItem (item, mList):

    if len(mList) == 0:
        print "no items in list"
        return 0
    
    maxi = mList[0][item]

    count = 0
    pos = 0
    for record in mList:
        if maxi < record[item]:
            maxi = record[item]
            pos = count
            
        count = count + 1
    return pos

def sortListUsingSelectionSort (item, mList):

    pos = 0
    for index in range(len(mList)):
        #The for loop should be filled with two lines of code
        #Both of which use one of the defined functions above
        #The first line is a bit tricky
        print "For loop in sortListUsingSelectionSort not yet implemented"

def sortListUsingBubbleSort (item, mList):

    print "sortListUsingBubbleSort not yet implemented"


def binarySearch (value, item, mList):

    print "binarySearch not yet implemented"

    

      
def main ( ):

    marksList = []
    inf = open ("marks.txt", 'r')

    inputMarks (marksList)
    printAllRecords (marksList)
    
    sortListUsingSelectionSort (STUDENT_ID, marksList)
    print "\n\nRecords for sorted list \n\n"
    printAllRecords(marksList);

    #Comment out previous sort before testing this one
    sortListUsingBubbleSort (STUDENT_ID, marksList) # Try with other fields as well
    print "\n\nRecords after bubble sort \n\n"
    printAllRecords(marksList);

    # This is an example of a test you might make on binary search
    # You might want to do further tests before submitting
    print binarySearch ("Halle", STUDENT_FIRST_NAME, marksList)



main ()

from the text document
M1234 Fred Johnson 18
H8732 Jane Brown 16
Y5663 Jerry Seinfeld 07
Y2345 Arnold Schwarzenegger 01
12331 Bruce Willis 19
N59248 Catherine Zeta-Jones 17
H4321 Tom Cruise 12
G83934 Halle Berry 15
T83289 Michelle Pfeiffer 18
U3823 Denzel Washington 14

a) Write a new function (called inputMarks) which will read the file marks.txt and place individual students records into a list (effectively a ‘list of lists’). The function should take the marks list as a parameter.

You may not assume that you know how many records are in the input file – it must work for any number of lines.

For each line in the input file you should create an individual list with four elements (listed above). Use the ‘split’ function to help you with this. Once you have created this list, add it to the marksList. The result of executing inputMarks should be a list of student records – one for each line in the file.

b) Write a function called calcGrade. This function takes a mark (type ‘int) and returns a grade. The grades are calculated as follows.

16 – 20 HD
14 – 15 D
12 – 13 C
10 – 11 P
< 10 F


c) Write a function called ‘printIndividualRecord’. It should take a list (corresponding to a single student record) as a parameter. If the record is


12331 Bruce Willis 19


the function should print out the details of the record in the following format


‘Willis, Bruce: Student number 12331 scored 19 / 20 – HD awarded’

d) Write a function called ‘printAllRecords’, which calls printIndividualRecord for each record in marksList. It should take marksList as a parameter.


Task B

Examine the functions already authored in assignment2.py.

• swap
• maxListByItem

In the code, write a high-level description of what each of these functions is intended to do as a comment above the function code. This description should be no longer than five lines. Marks will be awarded according to how well your response reflects your understanding.


Task C

Examine the function ‘sortListUsingSelectionSort’ that has been written in assignment2.py. This function is not complete. Use the functions from taskB to complete the implementation of this function. Note – it should not be necessary to move (change the order of) or delete the code that is already there.

When complete the function should have sorted the list in descending order (biggest item first).

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format all code that you post.

hey share the answer with this question

any answer for this thread?

please help

Edited 5 Years Ago by peter_budo: Forum flooding

At least instructors are giving out nice homework problems.
So, what is your exact problem with your homework?

This article has been dead for over six months. Start a new discussion instead.