登录  注册

首页->Python练习题

已知字符串weather中存放了若干以逗号分隔的天气,如weather='sunny,rainny,windy,sunny,rainny,windy,sunny,windy,windy,sunny,sunny,windy',统计每种天气出现的次数。

答:WEATHER='SUNNY,RAINNY,WINDY,SUNNY,RAINNY,WINDY,SUNNY,WINDY,WINDY,SUNNY,SUNNY,WINDY'
WLIST = WEATHER.SPLIT(',')
RESULT = {W:WLIST.COUNT(W) FOR W IN WLIST}
PRINT('天气\T次数')
FOR R IN RESULT:
PRINT('{}\T{}'.FORMAT(R,RESULT[R]))
继续答题:下一题
微考学堂微考学社

更多Python练习题试题