Answer:
Hi Lizzie! Please find the answer with explanation below.
Explanation:
We can implement this question in many languages, and since the language is not indicated in the question, I have chosen Python 2.0 + to implement it in (for it to work in Python 3.0+ you will need to change the "raw_input" to "input". You can save the below code in a file called drinking_age.py.
cat drinking_age.py
age = raw_input("Please enter your age: ")
try:
age = int(age)
if age >= 21:
print("This user is allowed to drink alcohol")
elif age < 1:
print("Age cannot be less than 1")
else:
print("You have to wait " + str(21 - age) + " before legally being allowed to drink")
except ValueError:
print("Invalid input!")