第三周第二次作业

6-1 人

per_info={'first_name':'chen','last_name':'nan',
          'age':'18','city':'guang zhou'
          }
for first,last in per_info.items():
    print(first,':',last.title())

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
first_name : Chen
last_name : Nan
age : 18
city : Guang Zhou

Process finished with exit code 0

6-2 喜欢的数字

fri_num={
    'chen':2,
    'pei':8,
    'sun':10,
    'li':20,
    'zhao':11,

}
for first,last in fri_num.items():
    print(first.title(),':',last)

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Chen : 2
Pei : 8
Sun : 10
Li : 20
Zhao : 11

Process finished with exit code 0

6-3 词汇表:

vol_table={
    'if':'judge the statement!',
    'for':'perform the loop',
    'while':'perform the loop',
    'int':'declare an integer variable',
    'float':'declare a float variable'
}
for first,last in vol_table.items():
    print(first,":")
    print('\t',last)

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
if :
	 judge the statement!
for :
	 perform the loop
while :
	 perform the loop
int :
	 declare an integer variable
float :
	 declare a float variable

Process finished with exit code 0

6-5 河流:

vol_table={
    'the Yangtze River':['china'],
    'the Yellow River':['china'],
    'Mekong River':['China','Laos','Burma','Thailand','Cambodia','Vietnam']
}
for first,last in vol_table.items():
    print(first.title(),'run through ',end='')
    for x in last:
        print(x,end=', ')
    print()

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
The Yangtze River run through china, 
The Yellow River run through china, 
Mekong River run through China, Laos, Burma, Thailand, Cambodia, Vietnam, 

Process finished with exit code 0

6-6 调查:

favorite_languages={
    'jen':'python',
    'saran':'C',
    'edward':'ruby',
    'phil':'python',
}
search_list=['edward','phil','chen','li']
for x in search_list:
    if x in favorite_languages.keys():
        print(x,",thank you for your inquiry!")
    else:
        print(x,'please accept my investigation!')

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
edward ,thank you for your inquiry!
phil ,thank you for your inquiry!
chen please accept my investigation!
li please accept my investigation!

Process finished with exit code 0

6-7 人

per_info={'first_name':'chen','last_name':'nan',
          'age':'18','city':'guang zhou'
          }
per_info1={'first_name':'li','last_name':'ning',
          'age':'20','city':'hang zhou'
          }
per_info2={'first_name':'wang','last_name':'ning',
          'age':'16','city':'wen zhou'
          }
people=[per_info,per_info1,per_info2];
for person in people:
    for first,last in person.items():
        print(first,':',last.title())
    print()

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
first_name : Chen
last_name : Nan
age : 18
city : Guang Zhou

first_name : Li
last_name : Ning
age : 20
city : Hang Zhou

first_name : Wang
last_name : Ning
age : 16
city : Wen Zhou


Process finished with exit code 0

6-9 喜欢的地方:

friends_favor={
    'chan':['hang zhou','su zhou','wen zhou'],
    'li':['guang zhou','shan tou'],
    'wang':['bei jing','shang hai']
}
for x,y in friends_favor.items():
    print(x.title(),"'s favorite places are:")
    for place in y:
        print(place,end=', ')
    print()
    print()

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Chan 's favorite places are:
hang zhou, su zhou, wen zhou, 

Li 's favorite places are:
guang zhou, shan tou, 

Wang 's favorite places are:
bei jing, shang hai, 


Process finished with exit code 0

6-10 喜欢的数字

fri_num={
    'chen':[2,3,5],
    'pei':[8,11,23],
    'sun':[10,11,22],
    'li':[12,34,44],
    'zhao':[31,24,24,15],
}

for first,last in fri_num.items():
    print(first.title(),"'s favorite numbers are:")
    print(end='\t')
    for x in last:
        print(x,end=' ')
    print('\n')

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Chen 's favorite numbers are:
	2 3 5 

Pei 's favorite numbers are:
	8 11 23 

Sun 's favorite numbers are:
	10 11 22 

Li 's favorite numbers are:
	12 34 44 

Zhao 's favorite numbers are:
	31 24 24 15 


Process finished with exit code 0

6-11 城市:

citys={
    'new york':{
        'country':'The United States',
        'population':'8 million',
        'fact':'the Staples Center is in New York'
        },
    'houston':{
        'country':'The United States',
        'population':'2 million',
        'fact':'the Toyota Center is in Houston'
    },
    'boston':{
        'country':'The United States',
        'population':'500 thousand',
        'fact':'the TD Banknorth Garden is Boston',
    },
}

for city in citys.items():
    print(city[0].title(),': ')
    for first,second in city[1].items():
        print('\t',first,':',second)
    print()

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
New York : 
	 country : The United States
	 population : 8 million
	 fact : the Staples Center is in New York

Houston : 
	 country : The United States
	 population : 2 million
	 fact : the Toyota Center is in Houston

Boston : 
	 country : The United States
	 population : 500 thousand
	 fact : the TD Banknorth Garden is Boston


Process finished with exit code 0




  















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值