5-3
alien_color='green'
if alien_color=='green':
print('You get 5 points')
5-5
alien_color='yellow'
if alien_color=='green':
print('You get 5 points')
elif alien_color=='yellow':
print('You get 10 points')
else:
print('You get 15 points')
5-7
favorate_fruits=['apple','watermelon','banana']
if 'apple' in favorate_fruits:
print('You like apple')
if 'pear' in favorate_fruits:
print('You like pear')
if 'watermelon' in favorate_fruits:
print('You like watermelo0n')
if 'banana' in favorate_fruits:
print('You like banana')
if 'orange' in favorate_fruits:
print('You like orange')
5-10
current_users=['aaa','bbb','ccc','ddd','eee']
new_users=['fff','ggg','bbb','ccc','rrr']
for user in new_users:
if user in current_uses:
print('Please input another name')
else:
print('OK')
6-5
river_info={'nile':'Egypt',
'Changjiang':'China',
'Amazon':'Brazil',
}
for river ,country in river_info.items():
print(river+' run through '+country)
for river in river_info.keys():
print(river)
for country in river_info.values():
print(country)
6-8
pi={'kind':'dog',
'master':'xiaoming',
}
aa={'kind':'cat',
'master':'mike',
}
ff={'kind':'dog',
'master':'John',
}
pets=[pi,aa,ff]
for pet in pets:
print(pet)
6-11
cities={
'Guangdong':{
'country':'China',
'population':1000000,
'fact':'.....',
},
'New York':{
'country':'US',
'population':13000,
'fact':'.........',
},
'London':{
'country':'British',
'population':1500000,
'fact':'.........',
},
}
for city,info in cities.items():
print(city + ' is in ' + info['country'] + ' with a population of '+
str(info['population']) + '.' + ' And it happened that ' +info['fact'])