高级编程技术第三周作业

5.1

food='rice'
print("Is food == 'rice' ,i predict true")
print(food=='rice')
print("Is food == 'pork' ,i predict false")
print(food=='pork')
animal='dog'
print("Is animal == 'dog' ,i predict true")
print(animal=='dog')
print("Is animal == 'cat' ,i predict false")
print(animal=='cat')
plant='tree'
print("Is plant == 'tree' ,i predict true")
print(plant=='tree')
print("Is plant == 'grass' ,i predict false")
print(plant=='grass')
country='China'
print("Is country == 'China' ,i predict true")
print(country=='China')
print("Is country == 'America' ,i predict false")
print(country=='America')
subject='Maths'
print("Is subject == 'Maths' ,i predict true")
print(subject=='Maths')
print("Is subject == 'English' ,i predict false")
print(subject=='English')

5.5

alien_color ='green'
if alien_color=='green':
	print("You get 5 points")
elif alien_color=='yellow':
	print("You get 10 points")
else:
	print("You get 15 points")
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")
alien_color ='red'
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
favorite_fruits={'banana','watermalon','strawberry'}
if 'apple' in favorite_fruits:
	print("You really like apple")
else:
	print("You don't like apple")
if 'banana' in favorite_fruits:
	print("You really like banana")
else:
	print("You don't like banana")
if 'pitch' in favorite_fruits:
	print("You really like pitch")
else:
	print("You don't like pitch")
if 'watermalon' in favorite_fruits:
	print("You really like watermalon")
else:
	print("You don't like watermalon")
if 'orange' in favorite_fruits:
	print("You really like orange")
else:
	print("You don't like orange")
if 'grapes' in favorite_fruits:
	print("You really like grapes")
else:
	print("You don't like grapes")
if 'strawberry' in favorite_fruits:
	print("You really like strawberry")
else:
	print("You don't like strawberry")

5.10

current_users={'eric','rose','emma','carl','kelly'}
new_users={'Emma','Leon','kyle','Rose','RYAN'}
for user in new_users:
	if user.lower() in [current_user.lower() for current_user in current_users]:
		print("This name has been used,you need use other name.")
	else:
		print("This name has not been used.")
5.11
numbers=list(range(1,10))
for number in numbers:
	if number==1:
		print('1st')
	elif number==2:
		print('2nd')
	elif number==3:
		print('3rd')
	else:
		print(str(number)+'th')
6.2
favorite_numbers={'Leon':5,'Emma':7,'Carl':2,'Ryan':8,'Rose':6}
print("Leon love "+str(favorite_numbers['Leon']))
print("Emma love "+str(favorite_numbers['Emma']))
print("Carl love "+str(favorite_numbers['Carl']))
print("Ryan love "+str(favorite_numbers['Ryan']))
print("Rose love "+str(favorite_numbers['Rose']))
6.5
river_country={'Yellow River':'China','Nile':'egypt','Amazon':'Brazil'}
for river,country in river_country.items():
	print('The '+river+' runs through '+country)
for river in river_country.keys():
	print('The '+river)
for country in river_country.values():
	print(country)

6.8

dog={'Alaska':'Emma','Husky':'Leon','Teddy':'Ryan'}
cat={'Persian':'Kyle','Siamese':'Edward','Scottish Fold':'Rooney'}
fish={'Catfish':'Luke','Goldfish':'Roger','Carp':'Frankie'}
pets=[dog,cat,fish]
for pet in pets:
	for kind,human in pet.items():
		print(human+" have a "+kind)

6.10
favorite_numbers={'Leon':[2,5,8],'Emma':[1,7],'Carl':[2,6],'Ryan':[2,4,8],'Rose':[3,6]}
for human,numbers in favorite_numbers.items():
	print(human+" loves numbers:")
	for number in numbers:
		print('\t'+str(number))
6.11
Guangzhou={'country':'China','population':14498400,'fact':'has much delicious food'}
Paris={'country':'France','population':11000000,'fact':'is the capital of fashion'}
New_York={'country':'America','population':8510000,'fact':'is commercially developed'}
cities={'guangzhou':Guangzhou,'paris':Paris,'new_york':New_York}
for city,inf in cities.items():
	print(city+' is a city in '+inf['country']+' and it has a population of '+str(inf['population'])+' and it '+inf['fact'])

猜你喜欢

转载自blog.csdn.net/liangjan/article/details/79688437
今日推荐