写一段代码,用于识别姓名(first_name,last_name)
结合使用函数get_formatted_name()和while循环,以更正规的方式问候用户
面尝试使用名和姓跟用户打招呼
def get_formarted_name(first_name,last_name,middle_name=''): if middle_name: full_name=first_name+' '+middle_name+' '+last_name else: full_name=first_name+' '+last_name return full_name.title() while True: print(" Please tell me your name: ") f_name = input("First name: ") l_name = input("Last name: ") m_name = input("Middle name: ") formatted_name=get_formarted_name(f_name,m_name,l_name) print(" hello, "+formatted_name+"!") choice=input(" Do you want tell me another name? (y or n)") if choice == 'y': continue else: break