python中函数与while循环结合
1、
def a(first,last):
full = f"{first} {last}"
return full.title()
while True: ## 条件为真的话,一直循环
print("\n\nplease tell me your name:") ## 两个\n,每执行一次循环,空出两行
print("(enter 'q' to quit in any time)")
fname = input("first name:")
if fname == "q": ## 设置退出条件
break
lname = input("last name:")
if lname == "q":
break
name = a(fname,lname)
print(f"hello, {name}")
please tell me your name:
(enter 'q' to quit in any time)
first name:aaaaa
last name:bbbbb
hello, Aaaaa Bbbbb
please tell me your name:
(enter 'q' to quit in any time)
first name:mmmm
last name:nnnn
hello, Mmmm Nnnn
please tell me your name:
(enter 'q' to quit in any time)
first name:q