标签:冒号 als name run eval war 替换 one 有趣
person = {
	‘first_name‘ : ‘Higos‘,
	‘last_name‘ : ‘Jess‘,
	‘age‘ : 24,
	‘city‘ : ‘shanghai‘,
}
print(person[‘first_name‘])
print(person[‘last_name‘])
print(person[‘age‘])
print(person[‘city‘])
favorite_numbers ={
	‘chandler‘ : 69,
	‘joey‘ : 23,
	‘ross‘ : 85,
	‘rachel‘ : 12,
	‘phoebe‘ : 2
}
for key,value in favorite_numbers.items():
	print(f"{key}‘s favorite numbers is : {value}.")
想出你在前面学过的5个编程词汇,将它们用作词汇表中的键,并将它们的含义作为值存储在词汇表中。
以整洁的方式打印每个词汇及其含义。为此,你可以先打印词汇,在它后面加上一个冒号,再打印词汇的含义;也可在一行打印词汇,再使用换行符(\n )插 入一个空行,然后在下一行以缩进的方式打印词汇的含义。
glossary = {
	‘string‘ : ‘A series of characters.‘,
	‘comment‘ :‘A note in a program that the Python interpreter ignores.‘,
	‘list‘ : ‘A collection of items in a particular order.‘,
	‘loop‘ : ‘Work through a collection of items,one at a time.‘,
	‘dictionary‘ : ‘A collection of key-value pairs.‘,
}
for key,value in glossary.items():
	print(f"{key.title()} :\n\t{value}")
glossary = {
	‘string‘ : ‘A series of characters.‘,
	‘comment‘ :‘A note in a program that the Python interpreter ignores.‘,
	‘list‘ : ‘A collection of items in a particular order.‘,
	‘loop‘ : ‘Work through a collection of items,one at a time.‘,
	‘dictionary‘ : ‘A collection of key-value pairs.‘,
	‘key‘ : ‘The first item in a key-value in a dictionary.‘,
	‘value‘ : ‘An item associated with a key in a dictionary.‘,
	‘conditional test‘ : ‘A comparsion between two values‘,
	‘float‘ : ‘A numerical value with a decimal component.‘,
	‘boolean expression‘ : ‘An expression that evaluates to True or False‘,
}
for key,value in glossary.items():
	print(f"{key.title()} :\n\t{value}")
rivers = {
	‘Nile‘ : ‘Egypt‘,
	‘Yellow River‘ : ‘China‘,
	‘Mekong‘ : ‘Vietnam‘,
	‘Amazon River‘ : ‘Peru‘,
	‘Mississippi‘ : ‘American‘,
}
for river,country in rivers.items():
	print(f"The {river} runs through {country}")
for river in rivers:
	print(f"The river‘s named {river}")
for country in rivers.values():
	print(f"The country was {country}.")
favorite_languages = {
	‘jen‘ : "python",
	‘sarah‘ : ‘c‘,
	‘edward‘ : ‘ruby‘,
	‘phil‘ : ‘python‘,
}
for name,language in favorite_languages.items():
	print(f"{name.title()}‘s favorite language is {language.title()}.")
print("\n")
friends  =[‘jen‘,‘phil‘,‘chandler‘,‘phoebe‘]
for name in friends:
	if name in favorite_languages.keys():
		print(f"{name.title()}, thank you for taking the poll.")
	else:
		print(f"{name.title()}, please take our poll!")
person_1 = {
	‘first_name‘ : ‘Higos‘,
	‘last_name‘ : ‘Jess‘,
	‘age‘ : 24,
	‘city‘ : ‘shanghai‘,
}
person_2 = {
	‘first_name‘ : ‘Chandler‘,
	‘last_name‘ : ‘Bing‘,
	‘age‘ : 30,
	‘city‘ : ‘Los Angeles‘,
}
person_3 = {
	‘first_name‘ : ‘Ross‘,
	‘last_name‘ : ‘Geller‘,
	‘age‘ : 30,
	‘city‘ : ‘Los Angeles‘,
}
people  =[person_1,person_2,person_3]
for person in people:
	full_name = person[‘first_name‘]+‘ ‘+person[‘last_name‘]
	age = person[‘age‘]
	city = person[‘city‘]
	print(f"{full_name.title()}‘s age is {age},and he/she lives in {city}")
pet_0 = {
	‘pet‘ :‘Husky‘,
	‘owner‘ : ‘chandler‘,
}
pet_1 = {
	‘pet‘ : ‘monkey‘,
	‘owner‘ : ‘ross‘,
}
pet_2 = {
	‘pet‘ : ‘cat‘,
	‘owner‘ : ‘rachel‘,
}
pets =[pet_0,pet_1,pet_2]
for pet in pets:
	print(f"{pet[‘owner‘]}‘s pet is a {pet[‘pet‘]}")
favorite_places = {
	‘chandler‘ : {"shanghai","xian","beijing"},
	‘rachel‘ : {"chengdu","wuhan","hangzhou1"},
	‘joey‘ : {"haerbin","shenzhen","dongguan"},
}
for name,places in favorite_places.items():
	print(f"{name.title()}‘s favorite places are:")
	for place in places:
		print(f"\t{place.title()}")
favorite_numbers ={
	‘chandler‘ : [69,389],
	‘joey‘ : [23,21],
	‘ross‘ : [85,4],
	‘rachel‘ : [12,43,594,183],
	‘phoebe‘ : [2],
}
for name,numbers in favorite_numbers.items():
	print(f"{name.title()}‘s favorite numbers are:")
	for number in numbers:
		print(f"\t{number}")
cities ={
	‘shanghai‘ : {
		‘country‘ : ‘China‘,
		‘population‘ : ‘20 million‘,
		‘fact‘ : ‘The rich city of China‘,
	},
	‘Los Angeles‘ :{
		‘country‘ : ‘American‘,
		‘population‘ : ‘40 million‘,
		‘fact‘ : ‘the city fill with COVID-19‘,
	},
	‘Hangzhou‘ :{
		‘country‘ : ‘China‘,
		‘population‘ : ‘15 million‘,
		‘fact‘ : ‘The most beautiful city of China‘,
	}
}
for city,informations in cities.items():
	print("The city name is :"+ city)
	country = informations[‘country‘].title()
	population = informations[‘population‘]
	fact = informations[‘fact‘]
	print("\t"+city.title()+"  belongs to "+country+".")
	print(‘\t‘ +‘there are about ‘+ population +‘ people to lives‘)
	print(‘\t‘ +‘the fact of ‘ +city.title() +" is: "+fact)
标签:冒号 als name run eval war 替换 one 有趣
原文地址:https://www.cnblogs.com/CodingXu-jie/p/12762575.html