hw4(第四周)

# [7-1, 7-2, 7-3]
# 7-1
car = input('What kind of car would you like to rend? ')
print('Let me see if I can find you a ' + car)
# 7-2
if(int(input('How many people are there having dinner? ')) >= 8):
    print("There're no empty tables.")
else:
    print("There're still some empty tables.")
# 7-3
if(int(input('Input a number: ')) % 10 == 0):
    print("It's a multiple of 10.")
else:
    print("It's not a multiple of 10.")

# [7-4, 7-5, 7-6, 7-7]
# 7-4
ingredient = input('Input some ingredient of pizza. Input quit to stop.')
while ingredient != 'quit':
    print('We will use %s to make this pizza.'%ingredient)
    ingredient = input('Input some ingredient of pizza. Input quit to stop.')
# 7-5
while True:
    age = input('Input your age. Input quit to stop.')
    if age == 'quit':
        break
    age = int(age)
    if age < 3:
        print('Free.')
    elif age < 12:
        print('10 dollar.')
    else:
        print('15 dollar.')
# 7-6
active = True
while active:
    ingredient = input('Input some ingredient of pizza. Input quit to stop.')
    if ingredient == 'quit':
        active = False
    else:
        print('We will use %s to make this pizza.'%ingredient)
# 7-7
stars = '*'
while stars != '':
    print(stars)
    stars += '*'

# [8-1, 8-2]
# 8-1
def display_message():
    print('Function')
# 8-2
def favorite_book(title):
    print('One of my favorite books is ' + title)

if __name__ == '__main__':
    display_message()
    favorite_book('The Man Who Changed China')

# [8-3, 8-4, 8-5]
# 8-3, 8-4
def make_shirt(size, text='I love Python'):
    print('The size of this T-shirt is ' + size + ', and there is a text "' + text + '" on this T-shirt.')
# 8-5
def describe_city(name, country='China'):
    print(name + ' is in ' + country + '.')

if __name__ == '__main__':
    make_shirt('L')
    make_shirt('M')
    make_shirt('S', 'I love PHP')
    describe_city('Guangzhou')
    describe_city('Honolulu', 'America')
    describe_city('Yangzhou')

# [8-6, 8-7, 8-8]
# 8-6
def city_country(name, country):
    return name + ', ' + country
# 8-7
def make_album(singer, album_name, song_number=1):
    return {'singer':singer, 'name':album_name, 'number':song_number}
# 8-8
if __name__ == '__main__':
    print(city_country('Guangzhou', 'China'))
    print(city_country('London', 'Britain'))
    print(city_country('Á', 'B'))
    print(make_album('王绎龙', '电音之王', 10))
    print(make_album('大张伟', '倍儿爽'))
    print(make_album('A', 'B', 0))
    while True:
        string = input('Input a singer and a name of the album which was published by this singer. Input quit to exit. ')
        if string == 'quit':
            break
        album = string.split()
        print(make_album(album[0], album[1]))

猜你喜欢

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