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 trialCasper Rasmussen
2,093 PointsTypecasting?
In the create_row(self, num) method. The first if statement is never True, when I run the code.
I think it has something to do with types, since card.location and column are both of type string and num is of another type.
I can't make it work with typecasting, but I don't think you did any typecasting here either?
Thanks :)
3 Answers
Peter Vann
36,427 PointsHi Casper!
I assume you are referring to this line of code:
If card.location == f'{column}{num}':
The result of f'{column}{num}' would be a string, so the types would be the same (both are strings).
For example:
f"{2 * 37}"
would evaluate to the string '74'
Perhaps try something like
If card.location == f'{column}{num}':
print(card.location)
print(f'{column}{num}')
to see what's really going on (debug).
I hope that helps.
Stay safe and happy coding!
Casper Rasmussen
2,093 PointsThanks Peter!
I found the problem! It would never print anything inside the if statement, even though before the the if statement both
print(card.location)
print(f'{column}{num}')
Gave the exact same string.
turns out the problem was I wrote
'f{column}{num}'
instead of
f'{column}{num}'
in the condition
Peter Vann
36,427 PointsThanks for the update, Casper!
If it makes you feel any better, I often seem to have dyslexic typing fingers!?! Sometimes I think I should hire a proofreader!?!
And I don't what I used to do before I got Grammarly!?! LOL
Have a great week!
-Pete