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 Python Basics (2015) Letter Game App Letter Game Introduction

Javier Makmuri
Javier Makmuri
3,257 Points

Why doesn't this run properly on python 3.6??

instead of _ _ _ _ _ it only prints out 1 _ and the {}/7.format(len(bad_guess)) is buggy.

Javier Makmuri
Javier Makmuri
3,257 Points

import random fruits = ["apple", "strawberry", "grape", "melon", "lemon", "pear", "grapefruit", "starfruit", "lime", "banana", "kiwi" ]

while True: start = input("Press enter to start, or press 'Q' to quit!") if start == 'Q': break word= random.choice(fruits) wrong=[] right=[] while len(wrong)<7 and len(right) != len(list(word)): for letter in word: if letter in right: print(letter,end='') else: print('_',end='') print('') print("Strikes:{}/7".format(len(wrong))) guess = input("Guess a letter: ").lower() if len(guess) != 1: print("You can only guess a single letter!") continue elif guess in wrong or guess in right: print("You have already guessed that letter!") elif not guess.isalpha(): print("You can only guess letters!") continue if guess in word: right.append(guess) if len(right)==len(list(word)): print("You Win! The word was {}.".format(word)) break else: wrong.append(guess) else: print("You didn't guess it! The fruit was {}.".format(word))

Steven Parker
Steven Parker
231,269 Points

To make your code readable, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

1 Answer

Steven Parker
Steven Parker
231,269 Points

Since the code looks like it might work, I'd guess you may have an indentation error. Unfortunately, that is impossible to confirm in unformatted code.