csev / py4e

Web site for www.py4e.com and source to the Python 3.0 textbook

Home Page:http://www.py4e.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PY4E: Quiz: Dictionaries; #6

spit-toon opened this issue · comments

THIS IS QUESTION #6: (the way I see it).
*** On the discussion board for PY4E - [Dictionaries] THREAD: ([Dictionaries Quiz Wrong Answer?] BY: Roy Layden); this bug seems to have been posted to a thread and the issue still seems to be happening with multiple users, w/o a fix/solution, currently implemented that I have found.**** ( see below the question formatting for more information)

************** **** QUESTION: #6 ******** **************
Which of the following lines of Python is equivalent to the following sequence of statements assuming that counts are a dictionary?

LINES OF PYTHON:
if key in counts:
counts[key] = counts[key] + 1
else:
counts[key] = 1

ANSWERS:
1.) counts.get(key,-1) + 1
2.) (key in counts) + 1
3.) key + 1
4.) counts[key]
5.) counts[key]
6.) counts[key]
7.) (counts[key] * 1) + 1
8.) counts[key]
9.) counts[key]
10.) counts.get(key,0) + 1
END OF QUESITON #6***********************


I originally answered this question with the answer of "counts.get(key,0) + 1"; which seems to be the correct answer; from the discussion board, and searching on the internet. This is with multiple sources, suggesting this is also the correct answer. I verified this with additional sources. all of the sources I had researched; gave the result of: "counts.get(key, 0) +1".

I thought I maybe was wrong because I forgot to add "counts[key]". As maybe this could be correct; like it needed both answers to be deemed correct. However, selecting both did not work either. I have tried multiple things to see if I might have been missing something. like putting the answers in a code to substitute the original "lines of Python". I got a few possibilities; from trying all of the answers in this way, and clicking every answer except, (multiple) "counts[key]". I tried; many other variables, even making another account. Just to be able to try different other slightly possible answers. Nothing seemed to work. I have saved a copy of my notes if you would like to see all of the possible solutions I have tried. I feel like I attempted to find a solution; even creatively applying what I know. NOTHING, SEEMS to end in a "correct" result.

The question is a bit confusing; some possible answers could be correct, but it depends on the entire answer, OR just part of what the code does that is used in, "lines of Python", or how much related to the given code needs to be true. such as increasing the amount(count); or regardless of the current number. The result is set to 1, regardless of the starting number. So depending on how much of the execution of the "lines of Python" methods the answers follow; a true answer, does make a difference. Does the answer just need to increase the result by one? Does it need to always make sure the variable stays at 1? Does a possible solution, need to be exact? or does the result/output just need to be the same? So, I have tried multiple variations of the result. depending on how I "compare" the results, and/or process. Using the following understanding of the information/question:

""counts[key] = counts[key] + 1":
This statement increments the value associated with the key "key" in the dictionary "counts" by 1. It updates the existing value with the new one. If the key doesn't exist in the dictionary, it will throw an error.

"counts[key] = 1":
This statement assigns the value 1 to the key "key" in the dictionary "counts". If the key already exists, it will overwrite the previous value; effectively resetting its value to 1. Otherwise, it will create a new key-value pair.

"counts[key] = counts[key] + 1"
increments the value of counts[key] by 1.
"counts[key] = 1"
assigns the value of 1 to counts[key], effectively resetting it to 1.

BOTH:
Expressions 1 and 2 are related as they both involve assigning values to keys in the counts dictionary, but they serve different purposes. Expression 1 increments an existing count, while expression 2 sets the count to 1.
...................
there are several answers that; "would", increase the value by 1.
...................
so I understand the concepts, or at least it feels as I do. but am getting lost as far as the correct answer. I have attempted the quiz now ten times, so I am locked out from trying further. but I do not seem like I am the only one who is having this issue, and it seems that the community is coming up with the same conclusion, whether that is. A correct conclusion, or wrong.

please look into this issue...
thank you
warm regards.

ps...
if this is a bug; I am hoping my score on this exam can be adjusted. or listing what the actual correct answer is. thank you so much for taking the time and effort to put this course together!!

LINK:
https://www.py4e.com/mod/tdiscus/thread/3970?PHPSESSID=434ff9c88489384eb337993f9f9c425e

Hi, I have also fallen foul of this, the correct answer should be counts[key] = counts.get(key,0) + 1 but this isn't listed as an option, only counts.get(key,0) + 1 which is marked as incorrect.

Hi, I have also fallen foul of this, the correct answer should be counts[key] = counts.get(key,0) + 1 but this isn't listed as an option, only counts.get(key,0) + 1 which is marked as incorrect.

I did try "counts[key], counts.get(key,0) + 1"
selecting both items, as a possible solution. As well as all the other items listed above. all of which; gave an incorrect input/solution. just so you know; that in combination. does not work either.

still no response on the disscussion board