14, అక్టోబర్ 2025, మంగళవారం

program 42 .....to be edit...Write a program to accept student name and marks from the keyboard and creates a dictionary. Also display student marks by t

 def create_student_records():

    """

    Accepts student names and marks to create a dictionary.

    Keys are student names (strings), and values are marks (integers).

    """

    student_data = {}

    num_students = int(input("Enter the number of students: "))


    for i in range(num_students):

        name = input(f"Enter name for student {i+1}: ")

        while True:

            try:

                marks = int(input(f"Enter marks for {name}: "))

                if 0 <= marks <= 100:  # Assuming marks are between 0 and 100

                    break

                else:

                    print("Marks should be between 0 and 100. Please try again.")

            except ValueError:

                print("Invalid input. Please enter a number for marks.")

        student_data[name] = marks

    return student_data


def display_student_marks(student_data):

    """

    Displays the marks of a student by taking their name as input.

    """

    search_name = input("\nEnter the name of the student to search for marks: ")

    if search_name in student_data:

        print(f"Marks for {search_name}: {student_data[search_name]}")

    else:

        print(f"Student '{search_name}' not found in records.")


if __name__ == "__main__":

    student_records = create_student_records()

    print("\nStudent Records Dictionary:")

    print(student_records)


    display_student_marks(student_records)

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి