您的位置:首页 > 编程语言

《高级编程技术》第三周作业

2018-03-21 23:00 323 查看
5-6 人生的不同阶段:
# -*- coding: utf-8 -*-
age = 23
if age < 2:
print ('你是婴儿。')
elif age < 4:
print ('你正蹒跚学步。')
elif age < 13:
print ('你是儿童。')
elif age < 20:
print ('你是青少年。')
elif age < 65:
print ('你是成年人。')
else :
print ('你是老年人。')
5-7 喜欢的水果:
favorite_fruits = ['orange', 'pineapple', 'watermelon']
if 'apple' in favorite_fruits:
print ('You really like apple.')
if 'banana' in favorite_fruits:
print ('You really like banana')
if 'orange' in favorite_fruits:
print ('You really like orange.')
if 'watermelon' in favorite_fruits:
print ('You really like watermelon.')
if 'grape' in favorite_fruits:
print ('You really like grape.')
5-10 检查用户名:
current_users = ['Byrant', 'James', 'Durant', 'Harden', 'Curry']
new_users = ['Durant', 'Davis', 'HARDEN', 'Paul', 'Ingram']

for new_user in new_users:
if new_user.title() in current_users:
print ('Sorry,  user name ' + new_user+ ' has been used. Please enter another one.')
else :
print (new_user+' is a new user name.')<
9288
/pre>6-2喜欢的数字:
NBA_Players = {'Byrant':24, 'Jardan':23, 'Iverson':3, 'Duncan':21, "O'Neal":34}
for name, number in NBA_Players.items():
print (name + "'s number is "+ str(number))
6-5 河流:
rivers = {'nile':'egypt', 'yangtze':'china', 'amazon':'brazil'}
for river, country in rivers.items():
print ('The ' + river.title() + ' river runs through ' + country.title() + '.')
print ('\n')

for river in rivers.keys():
print (river.title())
print ('\n')

for country in rivers.values():
print (country.title())
6-8 宠物:
Rocco = {'Breed':'Bulldog' , 'owner':'Klay Tompson'}
Wangkeke = {'Breed':'Alaskan Malamute' , 'owner':'Wangsicong'}
Dami = {'Breed':'Chinese pastoral cat' , 'owner':'Ms.papi'}

pets = [Rocco, Wangkeke, Dami]

for pet in pets:
print (pet)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息