Program1(b)

 1. b. Develop a program to read the name and year of birth of a person. Display whether the person is a senior citizen or not.

Objective of the Program

  • To read string and numeric input from the keyboard

  • To perform age calculation using the current year

  • To apply conditional statements for decision making

  • To display meaningful output based on logical conditions



Logical Construction (Think Before You Code)

Let us clearly understand the logic before writing the program.

  1. The program must read the name of the person.

  2. The program must read the year of birth.

  3. The current year is required to calculate age.

  4. Age is calculated using the formula:  age = current_year – year_of_birth

  5. If the calculated age is greater than or equal to 60, the person is a Senior Citizen.

  6. Otherwise, the person is not a Senior Citizen.

  7. The program displays the result with the person’s name.

  8. 👉 The decision is based purely on the age condition.



Flowchart





Algorithm

  1. Start

  2. Read the name of the person

  3. Read the year of birth

  4. Set current year

  5. Calculate age

  6. If age ≥ 60

    • Display “Senior Citizen”

  7. Else

    • Display “Not a Senior Citizen”

  8. Stop



Python Program

⚠️ Students must complete the missing statements


# Program to check whether a person is a Senior Citizen

name = input("Enter name: ")

year_of_birth = int(input("Enter year of birth: "))

current_year = ____________

age = ____________ - ____________

if age >= ____________:

    print(name, "is a Senior Citizen")

else:

    print(name, "is not a Senior Citizen")



Probable Output

Case 1: Senior Citizen

Enter name: Ramesh
Enter year of birth: 1958
Ramesh is a Senior Citizen

Case 2: Not a Senior Citizen

Enter name: Anitha
Enter year of birth: 1998
Anitha is not a Senior Citizen


Important Concepts Used

  • input() function

  • Type conversion using int()

  • Arithmetic operation

  • Conditional statement (if–else)

  • Relational operator (>=)



Viva Voce Questions

  1. How is age calculated in this program?

  2. Why is the year of birth converted to integer?

  3. What happens if the current year is changed?

  4. Why is >= 60 used instead of > 60?

  5. Can this program work for future years?

  6. What data type is used to store the name?

  7. How can the current year be taken dynamically?



Procedure to Execute the Program

  1. Open Python IDLE / VS Code / Google Colab

  2. Create a new Python file

  3. Type the program

  4. Save the file with .py extension

  5. Run the program

  6. Enter inputs when prompted



Google Colab – Online Execution

👉 Click the link below to execute the complete working version of this program:
[https://colab.research.google.com/drive/1ID5DKz9uNmquANwdFiI75yWrsGAWVpyK?usp=sharing]


Program Explanation





Assignment for Students

  • Modify the program to take current year from the system

  • Extend the program to classify:

    • Child

    • Adult

    • Senior Citizen

  • Validate input to avoid invalid year values




Lab Record Instructions

Right Side of the Record
1. Problem Statement
2. Python Program
Write the following neatly on the right-hand side page:


Left Side of the Record
Write the following neatly on the left-hand side page:
3. Flowchart
4. Algorithm
5. Output
⚠️ Students must write ALL possible outputs.



-:END:-

Comments

Popular posts from this blog