What is wrong with this code? 😑 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is wrong with this code? 😑

I know that this error appears if we put commas between keys and values in dictionaries so it becomes a set. But I don’t see any commas, so I think I did I correct, but I still see this error. https://code.sololearn.com/cqacc6Eg1AIL/?ref=app

4th Nov 2022, 7:21 PM
ПолинаС
7 Answers
+ 3
Here, I tried to fix it for you, again, I do not speak the language but that should be enough to keep you going :) https://code.sololearn.com/cQgEwLm33bP1/?ref=app
4th Nov 2022, 8:34 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 4
It says there is an issue in this line. for q, a in questions.items(): Maybe it doesn't like the q, a part?
4th Nov 2022, 7:41 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
I think you misused the multiline string When making your question dictionary, try to avoid using """. If you need a new line in the question, consider using the new line character '\n' instead. questions = { 'question': 'answer', '2+2': '4', 'multi \n line \n question': 'cool', } I don't speak this language so forgive me if I misunderstood, but I hope this helps :)
4th Nov 2022, 7:45 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 2
Oh that really works! Thanks you so much!
4th Nov 2022, 8:36 PM
ПолинаС
+ 1
The problem is that the first string opens and the last one closes with """, while all other openings and closings use ". So, the "s don't close the strings - only the last """ does. And the whole contents inside the curly brackets become a single string. Independent values inside curly brackets make a set, not a dictionary. That's why it errors when you try to iterate as a dictionary. Solution: use consistent quoting for each string.
5th Nov 2022, 1:37 AM
Emerson Prado
Emerson Prado - avatar
0
Ok I’ll try to use \n maybe it will work)
4th Nov 2022, 8:15 PM
ПолинаС
0
No I tried \n and it still shows an error 🤷🏼‍♀️ Strange…(((
4th Nov 2022, 8:22 PM
ПолинаС