hw3(第三周)

# [5-1]
# 5-1
mouse = 'Jerry'
print("Is mouse == 'Jerry'? I predict True.")
print(mouse == 'Jerry')

print("Is mouse == 'Mickey'? I predict False.")
print(mouse == 'Mickey')

# [5-3, 5-4, 5-5, 5-6, 5-7]
# 5-3
alien_color = 'green'
if alien_color == 'green':
    print('You killed a green alien and you got 5 points.')

alien_color = 'red'
if alien_color == 'green':
    print('You killed a green alien and you got 5 points.')
# 5-4
if alien_color == 'green':
    print('You killed a green alien and you got 5 points.')
if alien_color != 'green':
    print('You killed a ' + alien_color + ' alien and you got 10 points.')

if alien_color == 'green':
    print('You killed a green alien and you got 5 points.')
else:
    print('You killed a ' + alien_color + ' alien and you got 10 points.')
# 5-5
def printResult(alien_color):
    if alien_color == 'green':
        print('You killed a green alien and you got 5 points.')
    elif alien_color == 'yellow':
        print('You killed a yellow alien and you got 10 points.')
    else:
        print('You killed a red alien and you got 15 points.')
printResult('green')
printResult('yellow')
printResult('red')
# 5-6
for age in range(0, 70, 3):
    if age < 2:
        print('Baby')
    elif age >= 2 and age < 4:
        print('Walking')
    elif age >= 4 and age < 13:
        print('Children')
    elif age >= 13 and age < 20:
        print('Teenager')
    elif age >= 20 and age < 65:
        print('Adult')
    elif age >= 65:
        print('Elder')
# 5-7
favorite_fruits = ['Apple', 'Banana', 'Carrot']
if 'Apple' in favorite_fruits:
    print('You really like apples!')
if 'Banana' in favorite_fruits:
    print('You really like bananas!')
if 'Carrot' in favorite_fruits:
    print('You really like carrots!')
if 'Watermelon' in favorite_fruits:
    print('You really like watermelons!')
if 'Tomato' in favorite_fruits:
    print('You really like tomatoes!')

# [6-1, 6-2, 6-3]
# 6-1
elder = {
    'first_name': 'Min',
    'last_name': 'Ezawa',
    'age': 90,
    'city': 'Yangzhou'
    }
for key in elder:
    print(elder[key])
# 6-2
favorite_number = {
    'ZD': 1,
    'XP': 2,
    'ZM': 3,
    'JT': 4,
    'JP': 5
    }
for name in favorite_number:
    print(name + ' likes %d.'%favorite_number[name])
# 6-3
d = {
    'int': 'Integer',
    'double': 'Double precision float',
    'break': 'Jump out of the loop',
    'return': 'Jump out of the function',
    'for': 'A kind of loop'
    }
for keyword in d:
    print(keyword + ': ' + d[keyword])

# [6-4, 6-5, 6-6]
# 6-4
d = {
    'int': 'Integer',
    'double': 'Double precision float',
    'break': 'Jump out of the loop',
    'return': 'Jump out of the function',
    'for': 'A kind of loop'
    }
for keyword, meanings in d.items():
    print(keyword + ': ' + meanings)
d['in'] = 'Contains'
d['import'] = 'Add package'
d['python'] = 'This language'
d['elif'] = 'Else if'
d['dict'] = 'Dictionary'
for keyword, meanings in d.items():
    print(keyword + ': ' + meanings)
# 6-5
riversInCountries = {
    'nile': 'egypt',
    'yangze': 'china',
    'mississippi': 'america'
    }
for river, country in riversInCountries.items():
    print('The %s runs through %s.'%(river.capitalize(), country.capitalize()))
for river in riversInCountries:
    print(river)
for country in riversInCountries.values():
    print(country)
# 6-6
favourite_languages = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python', 
    }
searchList = ['aaa', 'edward', 'jen', 'phil', 'sarah', 'serb']
for name in searchList:
    if name in favourite_languages:
        print('%s, thanks for survey.'%name.capitalize())
    else:
        print('%s, I\'d like to invite you to do a survey.'%name.capitalize())

猜你喜欢

转载自blog.csdn.net/weixin_38533133/article/details/79632678
今日推荐