Answer to Question #210307 in Python for Faizan Ali

Question #210307

Write a function to display the result of examination of students. Following requirements must be fulfilled: i. Read the names and marks of at least 5 students, data should be acquired from the user and saved as dictionary (using a function named getinfo) ii. Rank the top three students with highest marks (make a function named top3) iii. Give cash rewards. Rs. 5000 for first rank, Rs. 3000 for second rank, Rs. 1000 for third rank. Value cannot be modified (function name should be cashprize)


1
Expert's answer
2021-06-24T07:34:40-0400
student = {}


def getinfo(n):
    for i in range(n):
        name, mark = input().split()
        student[name] = int(mark)
        
def top3():
    keys = sorted(student, key=student.get)
    temp = list()
    for k in keys:
        temp.append(k)
    return temp[-1], temp[-2], temp[-3]
    
def cashprize(std):
    prize = 5000
    for name in std:
        if prize < 0:
            return
        else:
            print(f'{name} - {prize}')
            prize -= 2000




if __name__ == '__main__':
    getinfo(int(input('number of students !(>5)')))
    cashprize(top3())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS