霍格沃茲名企定向Python測試開發(fā)進(jìn)階22
python開發(fā)--測試代碼(函數(shù)和類)
測試函數(shù)
def get_formatted_name(first, last):?(已報(bào)名霍格沃茲測試課底部評)? ?"""Generate a neatly formatted full name."""
? ?full_name = first + ' ' + last ? ?return full_name.title()
函數(shù)get_formatted_name() 將名和姓合并成姓名,在名和姓之間加上一個空格,并將它們的首字母都大寫,再返回結(jié)果。為核實(shí)get_formatted_name() 像期望的那樣 工作,我們來編寫一個使用這個函數(shù)的程序。程序names.py讓用戶輸入名和姓,并顯示整潔的全名:
print("Enter 'q' at any time to quit.")while True:
? ?first = input("\nPlease give me a first name: ")
? ?if first == 'q':
? ? ? ?break
? ?last = input("Please give me a last name: ")
? ?if last == 'q':
? ? ? ?break
? ?formatted_name = get_formatted_name(first, last)
? ?print("\tNeatly formatted name: " + formatted_name + '.')
標(biāo)簽: