Advertisement
An0n0ym0usHacker

Dictionaries

Dec 29th, 2020
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. school_class = {}
  2.  
  3. while True:
  4.     name = input("Enter the student's name (or type exit to stop): ")
  5.     if name == 'exit':
  6.         break
  7.    
  8.     score = int(input("Enter the student's score (0-10): "))
  9.    
  10.     if name in school_class:
  11.         school_class[name] += (score,)
  12.     else:
  13.         school_class[name] = (score,)
  14.        
  15. for name in sorted(school_class.keys()):
  16.     adding = 0
  17.     counter = 0
  18.     for score in school_class[name]:
  19.         adding += score
  20.         counter += 1
  21.     print(name, ":", adding / counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement