0% found this document useful (0 votes)
22 views2 pages

Student Details and Senior Citizen Check

The document contains code for two Python programs. The first program reads a student's name, USN, and marks in three subjects, calculates total marks and percentage, and displays the results. The second program reads a person's name and year of birth, calculates their current age, and prints whether they are a senior citizen (over 60) or not.

Uploaded by

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

Student Details and Senior Citizen Check

The document contains code for two Python programs. The first program reads a student's name, USN, and marks in three subjects, calculates total marks and percentage, and displays the results. The second program reads a person's name and year of birth, calculates their current age, and prints whether they are a senior citizen (over 60) or not.

Uploaded by

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

1.a StudDetails.

py
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.
stName = input("Enter the name of the student : ")
stUSN = input("Enter the USN of the student : ")
stMarks1 = int(input("Enter marks in Subject 1 : "))
stMarks2 = int(input("Enter marks in Subject 2 : "))
stMarks3 = int(input("Enter marks in Subject 3 : "))
print("Student Details\n=========================")
print('Name :', stName)
print('USN :', stUSN)
print('Marks 1 :', stMarks1)
print('Marks 2 :', stMarks2)
print('Marks 3 :', stMarks3)
print('Total :', stMarks1+stMarks2+stMarks3)
print('Percent :',((stMarks1+stMarks2+stMarks3)/3))
print("=========================")
1.b Senior Citizen Check
[Link]
Develop a program to read the name and year of birth of a person. Display whether the
person is a senior citizen or not.
from datetime import date
perName = input("Enter the name of the person : ")
perDOB = int(input("Enter his year of birth : "))

curYear = [Link]().year
perAge = curYear - perDOB
if (perAge > 60):
print(perName, "aged", perAge, "years is a Senior Citizen.")
else:
print(perName, "aged", perAge, "years is not a Senior Citizen.")

Common questions

Powered by AI

The variable names in both programs are functional but somewhat terse. For improved clarity, adopting a consistent naming convention such as snake_case or camelCase would help. Instead of 'stMarks1', 'stMarks2', and 'stMarks3', variables could be named 'marks_subject1', 'marks_subject2', and 'marks_subject3' to be self-explanatory. This aids in maintainability and makes the code more accessible. Similarly, 'perName' could be 'person_name', providing immediate context to the reader.

To extend 'StudDetails.py' for more than three subjects, the use of data structures like lists or dictionaries to store subject marks would be beneficial. Instead of individual variables, marks could be collected into a list using a loop, allowing dynamic expansion. A list comprehension could then be used for summation and average calculations, reducing code repetition and increasing scalability to handle any number of subjects dynamically without altering existing logic significantly.

The program checks the senior citizen status by calculating the person's age and determining if it is greater than 60. The logic, while functional, only accounts for ages exactly 61 and above. Potential improvements could involve handling incorrect inputs, leap years in age calculations, and including international standards for senior citizenship if different from the age of 60. Additionally, handling edge cases such as entering future birth years or non-numeric input types could improve robustness.

The 'StudDetails.py' program directly takes user input through input prompts. However, it has no built-in mechanisms to ensure correct or valid input types. Inputs are accepted as strings by default, which are then cast to integers for marks. This can lead to pitfalls if non-numeric input is provided for marks, potentially causing type errors. Implementing input validation, such as checking if the input is numeric before casting it to integers, could mitigate these issues.

The 'StudDetails.py' program uses clear and labeled output messages that enhance readability, dividing sections using separators for clarity. However, it relies on plain print statements which, while simple, could be improved with formatted strings for more concise and scalable output management, especially if the structure or amount of data changes. Adding whitespace for better separation of logical output blocks could further increase user-friendliness.

To improve input handling in 'StudDetails.py', input validation could be implemented before processing. For example, using a try-except block around the integer conversion of marks could catch ValueError, allowing the program to prompt for valid input. Another improvement could involve using a loop to continuously request input until correct data types are entered, ensuring the program does not crash due to user input errors.

To modify the logic in 'ChkSnrCitzn.py' to account for half-birthdays, the program would need to calculate age considering months and possibly days. This requires fetching the current month and day, comparing them with the birth month and day, and adjusting the age calculation accordingly. An added complexity is handling birthdates where the current month-day combination has not yet been reached in the current year, which would delay incrementing the age by 0.5 until that point.

The 'StudDetails.py' program is designed to capture and display student details, including computing the total marks and percentage scored in three subjects. The program uses the input function to get the student's name, USN, and marks in three subjects. It calculates the total marks by summing these marks using Python's addition operator and computes the percentage by dividing the total marks by 3 (the number of subjects) and outputs these details with suitable print statements.

The 'datetime' library is a robust choice in 'ChkSnrCitzn.py' for obtaining the current date and performing date calculations. While similar functionality could be achieved using other methods or libraries, like time for basic operations or external packages for more complex date manipulation, the 'datetime' module is preferred for its simplicity and comprehensive built-in functions for date handling in Python.

In the 'ChkSnrCitzn.py' script, the current year is determined using the date module from Python's datetime library. Specifically, it uses date.today().year to fetch the current year. This is significant as it allows the program to compute the person's current age by subtracting their year of birth from the current year. The age is then used to ascertain whether the person qualifies as a senior citizen (age greater than 60 years) and displays an appropriate message based on this condition.

You might also like