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
Ivan Valderrama
Python Web Development Techdegree Student 10,588 PointsNeed explanation on this particular line
From this code snippet:
while len(bad_guesses) < 7 and len(good_guesses) != len(list(secret_word)):
for letter in secret_word:
if letter in good_guesses:
print(letter, end='')
else:
print('_', end='')
Initially I had the following line: .... print(letter, end = '' ) .... Basically spaces between end, equals and inverted commas, to which my code was never working properly. When I looked at the code given, that was the only difference between code working, and code failing. Btw, I was not given any error messages.
Can someone explain to me what exactly is happening here 'print(letter, end='')', and why can I not have any spaces?
2 Answers
john larson
16,594 PointsHi, print(end="") is a particular item that does a particular thing. wherever you put it instead having a new line start, it continues on the same line. It comes in handy for formatting things a particular way. That is, you want to STOP the printing from going to the next line.
>>> for num in nums:
... print(num)
...
1
2
3
4
>>>
or
>>> for num in nums:
... print(num, end="")
...
1234>>>
Ivan Valderrama
Python Web Development Techdegree Student 10,588 PointsThanks for that explanation John!
john larson
16,594 Points:)