Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

The Better with Set(ter) - get_guess() TypeError

Hi!

So I'm working alongside The Better with Set(ter) video, using my old letter game file. Before starting, I amended the variable names to match "correct", "misses", and "word" to make life easier, and I noticed at 1:16 the following function containing an operand instead of a comma:

while True:
    draw(misses, correct, word)
    guess = get_guess(misses+correct)

If applying this alone, you'll receive the following TypeError when starting the game:

Traceback (most recent call last):
File "letter_game_3.py", line 112, in <module>
play(done)
File "letter_game_3.py", line 69, in play
guess = get_guess(misses+correct)
TypeError: get_guess() missing 1 required positional argument: 'correct'

While I'm happy with the answer to be changing the operand back to a comma (as the get_guess() function requires both arguments), I'm really curious as to why this is there in Kenneth's script in the video -prior- to any refactoring, and what additional lines of code are already in place to make this work, apart from the def get_guess(guesses) change?

Thanks in advance for your help!

Steven Parker
Steven Parker
243,199 Points

Can you provide a link to the video and a time index where this can be seen?

Hi Steven, apologies I thought I posted this within the video's questions - please see video link:

https://teamtreehouse.com/library/the-better-with-setter-letter-game

So between 1:16 - 1:40, Kenneth explains that he's changed the def get_guess(misses, correct): function to def get_guess(guesses):, which is why he's adding the two as per the above code, however that doesn't work and returns the above TypeError even before changing the variables to sets.

Hope this makes sense!

1 Answer

Steven Parker
Steven Parker
243,199 Points

At this point, the "get_guess" function requires only one argument, as shown at 1:24 in the video on line 33.

Then at 1:34 he explains "with sets I can't use the plus operand" and goes on to say, "I have to use the union operand" when he changes the symbol to a vertical bar.