Answer to Question #165473 in Python for leen

Question #165473


Given a dictionary that tells you a person's major, write a Python function that, given a person's name and a major, returns `True` if that person is majoring that subject, and `False` otherwise. Also return false if the student is not in the list of students.  


1
Expert's answer
2021-02-21T19:50:09-0500
dict = {"Abhi": "Computer Science", "Virat": "Maths"}


def name_major(name, major):
    for key,val in dict.items():
        if name in dict and major == dict[name]:
            return True
        else:
            return False

print(name_major("Virat" , "Computer Science"))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS