0% found this document useful (0 votes)
18 views3 pages

Student and Age Analysis Program

The document contains two Python programs: the first program collects student details including name, USN, and marks in three subjects, then calculates and displays total marks and percentage; the second program reads a person's name and year of birth to determine if they are a senior citizen. The first program outputs student details and results based on input marks, while the second program checks age against the senior citizen threshold. Both programs utilize functions for organization and clarity.

Uploaded by

bhuvanck1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Student and Age Analysis Program

The document contains two Python programs: the first program collects student details including name, USN, and marks in three subjects, then calculates and displays total marks and percentage; the second program reads a person's name and year of birth to determine if they are a senior citizen. The first program outputs student details and results based on input marks, while the second program checks age against the senior citizen threshold. Both programs utilize functions for organization and clarity.

Uploaded by

bhuvanck1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Develop a program to read the student details like Name, USN, and Marks in three subjects.

Display
the student details, total marks and percentage with suitable messages
# Function to calculate total marks and percentage
def calculate_results(marks):
total_marks = sum(marks)
percentage = total_marks / len(marks)
return total_marks, percentage

# Function to get student details


def get_student_details():
# Input student details
name = input("Enter student name: ")
usn = input("Enter student USN: ")

# Input marks for three subjects


marks = []
for i in range(1, 4):
mark = float(input(f"Enter marks for subject {i}: "))
[Link](mark)
return name, usn, marks
# Function to display student details
def display_student_details(name, usn, marks):
total_marks, percentage = calculate_results(marks)
# Displaying results
print("\n--- Student Details ---")
print(f"Name: {name}")
print(f"USN: {usn}")
print(f"Marks in Subjects: {marks}")
print(f"Total Marks: {total_marks}")
print(f"Percentage: {percentage:.2f}%")

# Main function
def main():
# Get student details
name, usn, marks = get_student_details()

# Display the details


display_student_details(name, usn, marks)

# Execute the program


if __name__ == "__main__":
main()

Output

Enter the student's name: Aaliyah

Enter the student's USN: 123ABC

Enter marks for subject 1 (out of 100): 85

Enter marks for subject 2 (out of 100): 90

Enter marks for subject 3 (out of 100): 88

Student Details --- Name: Aaliya USN: 123ABC

Marks: [85, 90, 88]

Total Marks: 263 Percentage: 87.67%

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

# Function to calculate age


def calculate_age(year_of_birth):
current_year = 2024 # You can dynamically use datetime module to get current year
return current_year - year_of_birth

# Function to determine if the person is a senior citizen


def is_senior_citizen(age):
return age >= 60

# Main function to read input and display the result


def main():
# Read the person's details
name = input("Enter the person's name: ")
year_of_birth = int(input("Enter the person's year of birth: "))

# Calculate age
age = calculate_age(year_of_birth)

# Check if senior citizen


if is_senior_citizen(age):
print(f"{name} is a senior citizen.")
else:
print(f"{name} is not a senior citizen.")

# Run the main function


if __name__ == "__main__":
main()
Out put
Enter the person's name: Aaliya
Enter the person's year of birth: 1955
Alice is a senior citizen.

Enter the person's name: Aalice Enter the person's year of birth: 1985 Bob is not a senior citizen.

Common questions

Powered by AI

Using a static year such as 2024 for age calculation limits the program's flexibility, rendering it inaccurate in future years or past if the reference year changes. It requires manual updates to maintain accuracy, increasing the likelihood of errors. Dynamically fetching the current year eliminates this issue, ensuring the program remains accurate regardless of when it is executed .

Real-world applications might face challenges such as handling incorrect or incomplete year of birth data, dealing with edge cases where birth year is on cusp years making them borderline senior citizens, and privacy concerns in accessing or storing birth date information. Also, discrepancies in local definitions of 'senior citizen' based on context or individual preferences might require adaptive criteria beyond simple year-based calculation .

Loop structures like `for` loops facilitate iterative input processing, ensuring the program prompts for the exact number of entries needed without redundancies. By iterating over a range, the code is concise and adaptable to changes such as requiring input for a different number of subjects. This reduces the possibility of errors and makes it easier to maintain and understand the code logic .

The program first defines two functions: one for calculating total marks and percentage from a list of marks, and another for inputting student details such as name, USN, and marks. The `calculate_results` function computes the total by summing the marks and calculates the percentage by dividing the total by the number of subjects. The `get_student_details` function prompts the user for input and returns these details. In the main function, these steps are integrated to first gather input and then display results using a structured message format .

To determine if a person is a senior citizen, the program calculates the person's age by subtracting their year of birth from the current year (e.g., 2024). The program then checks if the calculated age is greater than or equal to 60. If so, the person is classified as a senior citizen .

To adapt the program for an arbitrary number of subjects, introduce a variable to accept the number of subjects as input. Use this variable in the loop that collects marks to determine iteration count. Considerations include validating that the number of subjects is sensible (positive integer), adjusting the calculation of percentage to account for varying numbers of marks, and ensuring user prompts are dynamically generated for clarity .

The logic for determining the age involves subtracting the year of birth from the current year to calculate the number of years that have passed. Using a fixed current year like 2024 simplifies the code but hard-codes the current year, which is not future-proof. Including dynamic current year calculation using the datetime module ensures the program remains accurate regardless of when it is run or modified, maintaining relevance and precision .

User-friendly output formatting greatly impacts the usability by making outputs easier to understand and interpret, reducing user errors. Well-formatted outputs with clear labels and logical flow enhance user satisfaction and engagement, enabling quick comprehension of the data presented. Consistent formatting also aids in establishing a professional interface, crucial for user confidence in software reliability .

Input validation can be improved by checking that the input marks are numerical values within a valid range (e.g., 0 to 100 for percentage scores). Implementing a try-except block can handle exceptions for invalid input types, and while loops can be used to repeatedly prompt the user until valid input is received. Additional prompts or error messages can guide users towards providing correct input .

Functions improve code readability by allowing logical separation of tasks, such as input handling and calculation. They enable reusability and easier maintenance since specific tasks are encapsulated within functions, reducing redundancy. Debugging becomes simpler as functions provide clear interaction points and scopes, which enhances the reliability and overall quality of the program .

You might also like