Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python code that asks users for their last name, validates it (i.e., checks it against business rules), and then displays it as confirmation

Write a Python code that asks users for their last name, validates it (i.e., checks it against business rules), and then displays it as confirmation with only the first letter capitalized, e.g., Smith. If the name is not valid per our business rules, the display should be Invalid Name instead.

The rules for last names at our business are:

Names must be no longer than 20 characters but must be at least two characters.

Names may have an apostrophe (e.g., ORourke) or a hyphen (e.g., Smith-Barnes) but no other punctuation, no spaces, and no numbers.

For example, we dont allow Smith Jr. (has space and period) or Smith III (has space).

Here is the code I have so far but it doesn't seem to work,

last_name = input("Enter your last name: ") length=len(last_name) rule_one=False if(length<=20 and length>=2): rule_one=True i=0 rule_two=True while i=65 and ord(last_name[i])<=90) is_upper_case=(ord(last_name[i])>=97 and ord(last_name[i])<=122) if(not(is_lower_case or is_upper_case or ord(last_name[i])==45 or ord(last_name[i])==39)): rule_two=False i=i+1 if(rule_one and rule_two): print(last_name[:1].upper() + last_name[1:].lower()) else: print("Invalid Name")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

7. Determine what feedback is provided to employees.

Answered: 1 week ago