Python Forum
Need help with word guessing prorgam! Getting error message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with word guessing prorgam! Getting error message
#1
Hi, I am trying to learn python and the book I am reading is having me create this program. This is what i have so far and I am getting an error on line 53 --- 'str' object is not callable. I am not sure what I am doing wrong. Any and all help is appreciated.

# Chapter 4 Program 4
# Computer picks a random word and the player has to guess the word
# Computer tells how many letters are in the word
# Player gets 5 chances to ask if a letter is in the word.
# Computer responds with yes or no
# Player must guess the word

import random

# Introduction

print("\nIn this game you must guess a word that a computer randomly generates.",
      "\n\tThe computer will tell you how many letters are in the word.",
      "\n\tYou will have 5 chances to ask if a letter is in the word.")
input("\n\t\t PRESS ENTER TO BEGIN")
      
# Instert tuple

WORDS = ("archer","universe","castle","pretzel","rocky","illinois","programming")

# CHECK - DELETE LATER

print("Count of WORDS list", len(WORDS))
#---------------------------------------




word = random.choice(WORDS)

length = len(word)

placeholder = ""

print("\nThere are ",length,"letters in the word.")

print("\nYou now have 5 chances to ask if a letter is in the word.")

print("\nThe computer will respond with 'Yes' or 'No'")

print("\n\tUse lower case.")

#CHECK - DELETE LATER
print("THE WORD IS ------- " , word)
#-----------------------------
counter = 5
while counter !=0:
    answer = input("\nWhat is your first guess?")
      
      # Calculates if players answer is in the word
    for i in range(1, length, 1):
        
        if answer == word(length):
            placeholder = "Yes "
        else:
            placeholder = "No "
        print(placeholder)
        
Reply
#2
word holds a single word.
word(length) is supposed to do what??
first the syntax is wrong.
what you want is:

if answer == word:
Reply
#3
I am trying to see if the letter that the player guessed is in the word. So I am trying to write the code that it will slice the word and check each letter in the word individually. If the player guesses a letter in the word then the computer will reply "yes", and if the player guesses a letter that is not in the word that the computer generated then the computer will respond with "no". Answer will be equal to one letter. I tried putting word(length} as word[length] to slice it but it is not working.
Reply
#4
to get a specific letter of a word, you would use word[index] with
index being any number from 0 to length -1 of the word.
word[length] will fail since the first letter is word[0]

so to get each letter of word:
for i in range(length):
    print(word[i])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 933 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Another Error message. the_jl_zone 2 943 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,685 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  understanding error message krlosbatist 1 1,856 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  Error message pybits 1 36,064 May-29-2021, 10:26 AM
Last Post: snippsat
  f-string error message not understood Skaperen 4 3,268 Mar-16-2021, 07:59 PM
Last Post: Skaperen
  Overwhelmed with error message using pandas drop() EmmaRaponi 1 2,300 Feb-18-2021, 07:31 PM
Last Post: buran
  Winning/Losing Message Error in Text based Game kdr87 2 2,927 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  Don't understand error message Milfredo 2 1,995 Aug-24-2020, 05:00 PM
Last Post: Milfredo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020