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}: "))
marks.append(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.