Question: How do I get the following Python code to print a valid last name with the first character capitalized when the name is valid? def

How do I get the following Python code to print a valid last name with the first character capitalized when the name is valid?

def check_length(last_name): if((len(last_name) <2 or (len(last_name)>20))): return 0 else: return 1 def check_apostrophe_hyphen(last_name): if(('\'' in last_name) or ('-' in last_name)): return 1 else: return 0 def main(): length_not_matched =0 apostrophe_hyphen_not_matched =0 last_name= input("Please enter last name: ") while(check_length(last_name)==0 or check_apostrophe_hyphen(last_name)==0): if(check_length(last_name)==0): print("The last name should be between 2-20 characters!") length_not_matched=length_not_matched +1 elif(check_apostrophe_hyphen(last_name)==0): print("The last name should not contain any characters other than an apostrophe or a hyphen!") apostrophe_hyphen_not_matched = apostrophe_hyphen_not_matched +1 last_name = input("Please enter a last name: ") print(" {} is a valid last name.".format(last_name)) print("Number of times input did not match length criteria = {} ".format(length_not_matched)) print("Number of times input did not match apostrophe-hyphen criteria = {} ".format(apostrophe_hyphen_not_matched)) if __name__ =='__main__': main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!