Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # create a list of names and scores :
- studentScores = {'cheeky':100, 'arse':95, 'lankan':85}
- # display items in the dictionary
- print(list(studentScores.keys()))
- # variables to hold the values:
- # initalized to some dummy values
- minstudent = maxstudent = None
- minscore = maxscore = studentScores.values()[0]
- for student, score in studentScores.items():
- if score >= minscore:
- maxscore = score
- maxstudent = student
- elif score <= maxscore:
- minscore = score
- minstudent = student
- print('min student %s score %d' % (minstudent, minscore))
- print('max student %s score %d' % (maxstudent, maxscore))
- # eof
Add Comment
Please, Sign In to add comment