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
Login to like

Posted By:

Author Profile

UmairMehmood

11 days ago

Join the conversation!

Login to Comment

Discover More Articles

Sort a List Manual Bubble Sort using Loops in Python

Opening a Bank Account for Minors in Pakistan: A Comprehensive Guide

Jazz Summer Internship Program 2025 For All Pakistan Fresh Graduates

ASSISTANT PROFESSOR OF ENDOCRINOLOGY PPSC Jobs 14/2025 in SPECIALIZED HEALTHCARE & MEDICAL EDUCATION DEPARTMENT

پاکستانی ڈاکٹر کو کینیڈا کے بڑے سول اعزاز آرڈر آف کینیڈا سے نواز دیا گیا

پاکستانی ڈاکٹر کو کینیڈا کے بڑے سول اعزاز 'آرڈر آف کینیڈا "سے نواز دیا گیا

INSPECTORATE OF MINES, PUNJAB, MINES & MINERALS DEPARTMENT 2025 - 14/2025

PPSC Jobs - Male and Female Assistant Registrar Cooperative Societies 2025

Explain with specific example the relationship of higher education with employment situation in the developing countries.

Dengue Fever: Comprehensive Guide on Prevention, Treatment, and Health Guidelines