Python入门习题大全——城市名

Python入门习题大全——索引

编写一个名为city_country()的函数,它接受城市的名称及其所属的国家。这个函数应返回一个格式类似于下面这样的字符串:
“Santiago, Chile”
至少使用三个城市-国家对调用这个函数,并打印它返回的值。

# 城市名
def city_country(name, country):
    message = name + ", " + country
    return message

while True:
    print("\nPlease enter message: ")
    print("(enter 'q' at any time to quit)")

    city = input("name: ")
    if city == 'q':
        break
    country = input("country: ")
    if country == 'q':
        break
    message = city_country(city, country)
    print(message)

输出为:
(依次输入ling,a,huihe,b,q)

Please enter message: 
(enter 'q' at any time to quit)
name: ling
country: a
ling, a
Please enter message: 
(enter 'q' at any time to quit)
name: huihe
country: b
huihe, b
Please enter message: 
(enter 'q' at any time to quit)
name: q

Process finished with exit code 0
发布了269 篇原创文章 · 获赞 18 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_43479432/article/details/105425500