标签:for color lse python函数 choice fir div 识别 姓名
写一段代码,用于识别姓名(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("\nPlease 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("\nhello, "+formatted_name+"!") choice=input("\nDo you want tell me another name? (y or n)") if choice == ‘y‘: continue else: break
标签:for color lse python函数 choice fir div 识别 姓名
原文地址:https://www.cnblogs.com/show530/p/12431631.html