Write an if-elif-else chain that determines a person’s stage of life. a) Set your age for the variable age. b) If the age is less than 0, print an error message, invalid age. c) If the age is less than 2 years old, print a message, you're a baby. d) If the age is at least 2 years old but less than 4, print a message, you're a toddler. e) If the age is at least 4 years old but less than 13, print a message, you're a kid. f) If the age is at least 13 years old but less than 20, print a message, you're a teenager. g) If the age is at least 20 years old but less than 65, print a message, you're an adult. h) If the age is 65 or older, print a message, you're an elder. Example Output Age 20 You're an adult.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 7PP
icon
Related questions
Question
100%

need help with python

**Exercise 2: Age-Based Stage of Life Classification**

Objective: Write an `if-elif-else` chain to categorize a person’s life stage based on their age.

Instructions:

a) Assign your age to the variable `age`.

b) If `age` is less than 0, display an error message: "invalid age."

c) If `age` is less than 2 years, display: "you’re a baby."

d) If `age` is between 2 years (inclusive) and 4 years, display: "you’re a toddler."

e) If `age` is between 4 years (inclusive) and 13 years, display: "you’re a kid."

f) If `age` is between 13 years (inclusive) and 20 years, display: "you’re a teenager."

g) If `age` is between 20 years (inclusive) and 65 years, display: "you’re an adult."

h) If `age` is 65 years or older, display: "you’re an elder."

**Example Output:**

- Input: `Age = 20`
- Output: "You’re an adult."

Note: This exercise helps in understanding conditional statements in programming by categorizing age ranges into specific life stages.
Transcribed Image Text:**Exercise 2: Age-Based Stage of Life Classification** Objective: Write an `if-elif-else` chain to categorize a person’s life stage based on their age. Instructions: a) Assign your age to the variable `age`. b) If `age` is less than 0, display an error message: "invalid age." c) If `age` is less than 2 years, display: "you’re a baby." d) If `age` is between 2 years (inclusive) and 4 years, display: "you’re a toddler." e) If `age` is between 4 years (inclusive) and 13 years, display: "you’re a kid." f) If `age` is between 13 years (inclusive) and 20 years, display: "you’re a teenager." g) If `age` is between 20 years (inclusive) and 65 years, display: "you’re an adult." h) If `age` is 65 years or older, display: "you’re an elder." **Example Output:** - Input: `Age = 20` - Output: "You’re an adult." Note: This exercise helps in understanding conditional statements in programming by categorizing age ranges into specific life stages.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning