37-Dictionaries_simple_example_intro.py


Sign up Free. Don't forget to check out our challenges, lessons, solve and learn series and more ...


Code Snippet

def main():
    #create a dictionary to store teachers and the subject they teach
    teacher_details={"Mr Moose":"Philosophy","Mrs Snib":"Computing"}
    print(teacher_details)

    teacher=input("Which teacher are you after?:")
    if teacher in teacher_details:
        print(teacher, "teaches:", teacher_details[teacher])
        

main()
                    

Try it yourself