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

Ikechukwu Arum
Ikechukwu Arum
5,337 Points

can anybody pls help me? My code is giving me an error guess = input("Guess a letter: ").lower() TypeError: 'str' obj

import random

fruits = ["Orange", "Peach", "Apple", "Banana", "Pineapple","Pear","Cantalope","Mango","Plum","Melon","strawberry"]

while True: start = input = ("Press enter/return to start, or enter Q to quit ") if start.lower() == "q": break

pick a random word

fruit_type = random.choice(fruits)
bad_guesses = []
good_guesses = []

while len(bad_guesses) < 7 and len(good_guesses) != len(list(fruit_type)):
    #draw spaces
    for letter in fruit_type:
        if letter in good_guesses:
            print(letter,end = "")
        else:
            print(" ",end = "")
    print(" ")
    print ("Strike: {}/7 ".format(len(bad_guesses)))
    print(" ")

    #take guess
    guess = input("Guess a letter: ").lower()


    if len(guess)!= 1:
        print("You can only guess a single letter! ")
        continue
    elif guess in bad_guesses or guess in good_guesses:
        print("You've already guess that letter ")
        continue
    elif not guess.isalpha():
        print("you can only guess alphabets!")
        continue


    if guess in fruit_type:
        good_guess.append(guess)
        if len(god_guesses) == len(list(fruit_type)):
            print("You win! The word was {}".format(fruit_type)) 
            break
    else:
        bad_guesses.append(guess)

else: print("You didn't guess it! the fruit type was {}".format(fruit_type))

1 Answer

Wesley Trayer
Wesley Trayer
13,812 Points

Took a little searching but I found it!

while True: start = input = ("Press enter/return to start, or enter Q to quit ") if start.lower() == "q": break
#                         ^
# Should not have equal sign after "input"

This should fix the 'str' error.

Hope this answers your question. :-)