Discussions Events Study Material Jobs
Use a nested dictionary of students and their subject marks Using Python - Uniwaly

Explore Diverse Conversations


Use a nested dictionary of students and their subject marks Using Python

Posted By: UmairMehmood Published On: 13 June 2025 At: 13:02 PM

Ask user to input a student name and subject, and display the corresponding mark
 data = { "Ali": {"Math": 85, "Science": 90}, "Sara": {"Math": 78, "Science": 88} } 


Code:

data = {
    "Ali": {"Math": 85, "Science": 90},
    "Sara": {"Math": 78, "Science": 88}
}
 
student_name = input("Enter the student's name: ")
subject_name = input("Enter the subject: ")
 
if student_name in data:
    if subject_name in data[student_name]:
        print(f"{student_name}'s mark in {subject_name} is {data[student_name][subject_name]}")
    else:
        print(f"Subject '{subject_name}' not found for {student_name}.")
else:
    print(f"Student '{student_name}' not found.")



Tags:

python nested dictionary python nested dictionary

Posted By:

Author Profile

UmairMehmood

1 month ago
Login to like

Join the conversation!

Login to Comment

Discover More Articles

Create a tuple of 6 items and print its length using len() function Using Python

Jobs in Excise and Taxation

CM Punjab Asaan Karobaar Card Scheme

Discuss the need of new professional profile of teaching staff in order to survive in this competitive era.

Rescue 1122 Punjab Jobs 2025 For Multiple Categories

New 30,000 Teaching Jobs Coming Soon on Merit : CM Punjab

INTERVIEW FOR THE POSITION OF WEB DEVELOPER IN THE URBAN SECTOR PLANNING & MANAGEMENT SERVICES UNIT "THE URBAN UNIT

Web Developer Jobs In Urban Unit for Fresher

Write a program to calculate the sum of all elements in a list using a for loop using Python

Pakistani Provices , Districts and Cities Dropdown Using JSON with name,uid,cities