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 trialKylie Nonemaker
1,190 PointsLooking for clarification on the check_location method
Hey community!
Hoping someone can explain how the "time" works in the below method? This is from the video Game Class Part 3 in Basic Object-Oriented Python.
def check_location(self, time):
while True:
guess = input(f"What's the location of your {time} card? ")
if guess.upper() in self.locations:
return guess.upper()
else:
print("That's not a valid location. It should look like this: A1")
Is "Time" just something that works without us setting the attribute in any way?
1 Answer
Steven Parker
231,269 PointsIn a formatted string (identified by the letter "f" in front), any variable name surrounded by braces will be substituted using the value of that variable. For example, if that method was called and "purple" was passed as the argument, the question shown for the input would look like:
What's the location of your purple card?