Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2"""Solution to chapter 4, exercise 15: rainfall""" 

3 

4 

5def get_rainfall(): 

6 rainfall = {} 

7 

8 while True: 

9 city_name = input("Enter city name: ") 

10 if not city_name: 

11 break 

12 

13 mm_rain = input("Enter mm rain: ") 

14 rainfall[city_name] = rainfall.get(city_name, 0) + int(mm_rain) 

15 

16 for city, rain in rainfall.items(): 

17 print(f"{city}: {rain}")