Question: I am working my way through Python Crash Course, and in Chapter 8 the author gives the following code as an example for filling a dictionary with user input. I am confused in the step where he stores the responses into the dictionary, as to my eye it looks as though he is only saving one piece of , "response" which is immutable data to the "responses" dictionary under the key "name". I am missing how both the name input and response input are put into the dictionary.

It seems to make no sense to me, but that is what I have loved about this journey so far, finding sense in seeming nonsense. Thank you for helping demystify this world for me.

```
responses = {}

# Set a flag to indicate that polling is active.
polling_active = True

while polling_active:
    #Prompt for the person's name and response.
    name = input("\nWhat is your name? ")
    response = input("Which mountain would you like to climb someday? ")

    #Store the response in the dictionary:
    responses[name] = response

    #Find out if anyone else is going to take the poll.
    repeat = input("Would you like to let another person respond? (yes/no) ")
    if repeat == 'no':
        polling_active = False

#Polling is complete.  Show the results.
print("\n--- Poll Results ---")
for name, response in responses.items():
    print(name + " would like to climb " + response + ".")

```

Answer: 
As a quick fix, add [commit](https://pymssql.readthedocs.io/en/stable/ref/pymssql.html#pymssql.Connection.commit) after `execute`:

```
...
cursor.execute(sql)
cursor.connection.commit()

```

But I would also advise you to keep as little connections as possible. In your current code you create new connection for each operation.
After inserting with your cursor you need to commit your inserts with `connection.commit()`

As qaziqarta pointed out it is best practice to not open a new connection everytime you are trying to insert or read something from the database.

You should initialize your connection once at the beginning and close it after you are done reading/writing.