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 trialWendy Turner
718 PointsAll Fruits make one word?
I am using Notepad ++ to try this myself, but the secret word is a run on of all the fruits put together. Is it because the import of the random feature isn't working? Also, How can I post a picture of my code in the question box?
2 Answers
Steven Parker
231,275 PointsI'd have to see your code to comment on the first question, but to post your code just cut-and-paste it inside a blockquote. To do that, skip a blank line, the put a line with only 3 accents and your language id (like: ```py), then your code, then a line with just 3 accents.
Even better, make a snapshot of your workspace and post the link to it here.
Wendy Turner
718 PointsThanks for the tip! Not only does it print all the fruits together as the chosen word every time, it prints the strikes: 0/7 exactly 7 times as well.
'''.py import random
Make a list of words
words = [ 'Apples', 'Mangos', 'Papaya', 'Tangerines', 'Rasberry', 'Watermelon', 'Grapes', 'Kiwis', 'Bananas', 'Strawberries', 'Limes'] while True: start = input("Press enter/return to start, or Q to quit") if start.lower() == "q": break
# Pick a random word
secret_word = random.choice(words)
bad_guesses = []
good_guesses = []
while len(bad_guesses) < 7 and len(good_guesses) != len(set(secret_word)):
# Draw guessed letters, spaces and strikes
for letter in secret_word:
if letter in good_guesses:
print(letter, end="")
else:
print("_", end="")
print("")
print("strikes: {}/7".format(len(bad_guesses)))
print("")
# Take Guesses
guess = input("Guess a letter: ").lower()
if len(guess) != 1:
print("You can only guess one letter at a time")
continue
elif guess in bad_guesses or guess in good_guesses:
print("You've already guessed that letter")
continue
elif not guess.isalpha():
print("You can only guess letters!")
continue
if guess in secret_word:
good_guesses.append(guess)
if len(good_guesses) == len(list(secret_word)):
print("You win! The word was {}".format(secret_word))
break
else:
print("The correct guesses so far are {}".format(good_guesses))
else:
bad_guesses.append(guess)
else:
print("You didn't guess it. My secret word was {}".format(secret_word))
# Print out win/lose
'''