Problem E
Validate Name and Age
Write a program that includes two functions, get_name() and get_age().
The get_name() function should prompt the user: "What’s your name? " If the user enters a string that does not consist of only alphabetical characters and spaces, and additionally has at least one alphabetical character, the function should print:
Please enter a valid name.
It should keep asking until the user supplies a valid name, and return the given name.
The get_age() function should prompt the user: "How old are you? ". If the user inputs a non-integer value, the function should print:
Please enter an integer.
If the user inputs a number that is strictly less than $0$ or strictly greater than $125$, then the function should print:
You seriously expect me to believe you are {age} years old?
It should keep asking until the user supplies a valid age, and return the given age.
The program should call both these functions and print out:
Nice to meet you {name}. Congratulations on your {age} years.
where {name} is the value returned from get_name() and {age} is the value returned from get_age().
Input
Input consists of user interactions providing the name and age as prompted by the program over multiple lines. The input consists of at most $5000$ symbols total and each one has an ASCII value in the range $32$ to $126$.
Output
Output consists of:
-
Possible prompts asking for valid input based on the criteria mentioned.
-
A final statement greeting the user using the provided name and age.
This can be on one line as above or two lines as in the samples, it does not matter.
Sample Input 1 | Sample Output 1 |
---|---|
Ben 57 |
What's your name? How old are you? Nice to meet you Ben. Congratulations on your 57 years. |
Sample Input 2 | Sample Output 2 |
---|---|
C3PO C three P O It has been thirty-two years since master Anakin created me. 32 |
What's your name? Please enter a valid name. What's your name? How old are you? Please enter an integer. How old are you? Nice to meet you C three P O. Congratulations on your 32 years. |
Sample Input 3 | Sample Output 3 |
---|---|
Yoda 900 Expect you to, I do. 900 A distraction, your belief is. 900 Narrow-minded, computers are. Accept 90, you will? 90 |
What's your name? How old are you? You seriously expect me to believe you are 900 years old? How old are you? Please enter an integer. How old are you? You seriously expect me to believe you are 900 years old? How old are you? Please enter an integer. How old are you? You seriously expect me to believe you are 900 years old? How old are you? Please enter an integer. How old are you? Please enter an integer. How old are you? Nice to meet you Yoda. Congratulations on your 90 years. |
Sample Input 4 | Sample Output 4 |
---|---|
I don't have a name yet, m8. Rey I suppose -1 0 |
What's your name? Please enter a valid name. What's your name? Please enter a valid name. What's your name? How old are you? You seriously expect me to believe you are -1 years old? How old are you? Nice to meet you Rey I suppose. Congratulations on your 0 years. |
Sample Input 5 | Sample Output 5 |
---|---|
James Bond 00700 007 |
What's your name? How old are you? You seriously expect me to believe you are 00700 years old? How old are you? Nice to meet you James Bond. Congratulations on your 007 years. |