Q1. Use a function to generate a full name with input of first name and last name. and use while could repeatedly print the full name and collect the first and last name from the users.
The output:
(enter "q" at any time you want to quit.)
please input your first name: sunny
please input your last name:sun
Sunny Sun
(enter "q" at any time you want to quit.)
please input your first name: love
please input your last name:you
Love You
(enter "q" at any time you want to quit.)
please input your first name: q
please input your last name:q
The codes:
def get_formatted_name(first_name,last_name):
full_name = first_name+' '+last_name
return full_name.title()
while True:
print('(enter "q" at any time you want to quit.)')
f_name = input('please input your first name: ')
l_name = input('please input your last name:')
if (f_name == 'q') or (l_name =='q'):
break
musician = get_formatted_name(first_name=f_name, last_name=l_name)
print(musician)
Q2: piggback the list in the function:
Hello,Hannah!
Hello,Bob!
Hello,Jack!
The codes:
def greet_users(names):
for name in names:
msg = 'Hello,'+ name.title()+'!'
print(msg)
user_names = ['hannah','bob','jack']
greet_users(user_names)