#๐ Difficulty understanding how to go about school assignment
50 messages ยท Page 1 of 1 (latest)
@turbid walrus
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Do you need help still
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
yes please, im not sure why my message got deleted
Im trying to create a script where I get an input about the number of books per genre, and the title of each book
but I cant figure out how to print each specific genre with its own titles
You're storing all the titles in the same genrelist without recording what genre they belong to, so that information is immediately lost.
It would be cleaner to do something like make the keys of the dictionary the genre names.
The assignment says to use the same nested list for each title, but it confuses me because it doesnt make sense
i thought about creating difference genres as keys, and then moving the titles to each corresponding list, but then what would be the point of the genreList?
It indeed doesn't make much sense since the dictionary is effectively useless then.
What are the exact instructions?
A screenshot would work too assuming the instructions aren't over multiple pages.
thank you ill do that
these are the instructions and an example of what the output is meant to look like
These instructions don't make much sense to me, I'll be honest.
I was worried I was missing something
It doesn't say what the purpose of inventory is for example, despite mandating its use.
yeah, maybe I do need to go ahead and create separate keys for each genre?
The "proper" way to tackle a problem like this would be to do something like make the dictionary keys the genre titles, and the value a new list.
Yes
Well, that's how I'd do it.
I don't know what they want.
okay thank you, I just wanted to make sure it wasnt just me that was confused
"genreList will be reused for each genre" and the lack of explanation on what inventory is for are the confusing parts.
genreList being "reused" is a bit confusing.
I'm not sure what they mean by "reuse", since that kind of suggests the list is wiped between genres or something.
i did make it so it got wiped before the next input, however that just made it so only the last stored list was printed
I also thought about adding it to genreList, and then adding it to each respective genre, but that seemed like an unnecessary extra step.
I was actually going to suggest that, but then I couldn't think of what genreList would even be used for.
I feel like there's some context missing. The "Start by modifying" instruction suggests there was previous context.
well there was a previous assignment I had, where I was supposed to ask the user for how many books were in each genre, and then printing the genres with books.
so for example if i put 1 for narrative, 4 for mystery, and 0 for fiction, it would only print narrative and mystery
The other way this could be done is by making the genreList hold dictionaries that hold both pieces of infiormation:
genreList = [{title: 'Blah', genre: 'Some Genre'}, {title: 'Blah 2', genre: 'Some Other Genre'}]
But inventory would do a better job than that for most cases,
So I have a question, does python support a dictionary in a list nested in another dictionary?
You can nest structures infinitely (assuming infinite memory).
You can't have a list as a key to a dictionary, but they can be nested forever as values.
so would I be able to put a dictionary in the genreList? and that would hold each genre? The name makes me think thats what it wants but I still dont understand what they want Inventory for
It confused me that they have me title it genreList and have it hold the titles
In theory, yes. There's nothing preventing you from doing that. But ya, that doesn't explain what inventory is for.
You might want to ask for clarification. There's only so much we can do with poor instructions.
Okay, if I cant figure it out by doing the dict list dict nesting structure then Ill ask for clarification
thank you
You're welcome.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.