O'Reilly logo
  • Longxiang Lyu thinks this is interesting:

6-10. Favorite Numbers:

From

Cover of Python Crash Course

Note

favorite_numbers = {'lucy': [1, 2, 3], 'joshua': [250, 32], 'bob': [32, 8], 'serena': [], 'ronald': [32]} for name in favorite_numbers.keys(): message = '\n' + name.title() + "'s favorite number" l = len(favorite_numbers[name]) if (l == 0): print('\n' + name.title() + ' has no favorite number.') continue elif (l == 1): message += ' is:' elif (l > 1): message += 's are:' print(message) for num in favorite_numbers[name]: print('\t' + str(num))