Saturday, January 21, 2017

Blog 42

What is the printout of the program below?

my_dict={}
my_dict["Jon"]=1000
my_dict["Bob"]=2000
my_dict["Sue"]=3

print my_dict[my_dict["Bob"]]

15 comments:

  1. 2000
    ~Travis Vonheeder

    ReplyDelete
  2. Key Error: 2000
    It prints out a key error because there is no value for 2000
    -Joe Haj

    ReplyDelete
  3. KeyError: 2000
    Technically, that is the error message, not what is printed.
    -Katelyn

    ReplyDelete
  4. my_dict={}
    my_dict["Jon"]=1000
    my_dict["Bob"]=2000
    my_dict["Sue"]=3

    print my_dict[my_dict["Bob"]]
    Charlie Lin

    ReplyDelete
  5. This program causes a KeyError because the value 2000, isn't a key-value pair. The value 2000 isn't a key.

    - Abby Peterson

    ReplyDelete