Question
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started