This is Jeopardy Challenge Project (Python, Pandas)

Anybody feel like helping me out?

I’m trying to build out a game, at the bottom of my project, but I’m stuck.

I’m trying to have the user select a category via input. I built out a dict with 6 random categories, shown like {1: ‘Category 1’, 2: ‘Category 2’…} but for the life of me I cannot figure out how to get it to work. As far as i can tell my code should work: it asks “if [user input] in [dictionary]” break and continue on, else tell them how to pick and try again. But typing the key doesn’t work, it doesn’t think it’s in the dictionary, which is how I thought it should work; typing the item doesn’t help either, so I don’t know what it thinks is in the dictionary. Can you take a look at my code and tell me where I’ve gone wrong? GitHub - brothertrance/This-is-Jeopardy-Terrance: Project Repository for This Is Jeopardy by Terrance

Much appreciated!

Hey Terrance, I looked at your code. ‘categories’ is a dictionary, so you need to just change one line:
catans in categories to catans in categories.values()

This should work because the category is a value in the dictionary. When using ‘in’, it checks the keys. Even when you type the number in your code, it still returns False. This is because the key is an integer while the input from the user is a string.

Hope this helps and happy coding!

Ugh thank you! That was driving me bananas.

Big thanks to @robertpal7899360306 for the code help, here’s my final (for now) version, down at the bottom I built out a whole game if you want to play around! Or just give me any tips or pointers in my code, that’s awesome too.

(Yes I know I need to get better at commenting in my code, I’m working on it. Right now I’m lazy.)

Glad you got your game to work! Well done.

1 Like

Hello guys, I’ve tried to look up keyword like REGEX here and Google. Still, I couldn’t find a way to solve the problem. Can anyone here help me out? I’d be really appreciated! :pleading_face:

So, in task 3 about the filter function, it said

You may also want to check to make sure you don’t find rows that contain substrings of your given words. For example, our function found a question that didn’t contain the word "king" , however it did contain the word "viking" — it found the "king" inside "viking"

If I don’t want the filter function to count VIKING in the searching for KING the keyword. Or, don’t count ‘England’s’ with the keyword ‘England.’ How do I apply regex in my function?

I know I could probably add regex ‘\s’ before and after the keyword.But how exactly I can apply the regex, in this case, to a list of words?

I’ve come up with something like this. But apparently it didn’t work…

import re def regex_filter_data(data, words): pat_words = [] filtered_df = pd.DataFrame() for word in words: pat = r'\s{word}\s' pat_words.append(pat) for word in pat_words: pd.concat([filtered_df, data[data['Question'].str.contains(pat=word, na = False, case=False, regex=True)]]) return filtered_df print(regex_filter_data(df, ['king', 'England]))

Hello Codecademy!

Here is my solution to the “This is Jeopardy” project. All feedback is welcome!

Happy coding!