#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    33
    Rep Power
    9

    If you have question post it here!, also if your expierenced in python, answer here!


    i probably cant answer your question but hopefully others will look here to help you.

    i got a question.when i try to run this:

    import random

    WORDS = ("bob", "lord", "world", "hero", "ball")
    word = random.choice(WORDS)

    print "There are ", len(word), "letters in the word"
    print "you have 5 chances to guess a letter in the word"
    print "then you must guess the word"

    chance = 0

    while chance != 6:
    chance += 1
    guess = raw_input("A letter guess: ")
    guess = guess.lower
    if guess in word:
    print "yes"
    else:
    print "no"

    wordguess = raw_input("The word guess: ")
    if wordguess == word:
    print "YES! you got it"

    else:
    print "nope, it is", word

    raw_input("Press enter to exit")


    it says:
    traceback (most recent call last):
    File "C:\Python22\Programs\guess my word", line 16, in ?
    if guess in word:
    TypeError: 'in <string>' requires character as left operand

    it says that after i type in a letter at
    guess = raw_input("A letter guess: ")

    and there is a space at the 'while' command but it doesnt show on forums.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Code:
    guess = guess.lower
    Here is the mistake. guess is now a function What you want is
    Code:
    guess = guess.lower()
    Regards, mawe
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    33
    Rep Power
    9
    thank you for the tip, ill try it
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    33
    Rep Power
    9
    oopse nvm
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Yes, it will error out because you're missing a closing quote in the last statement. Seriously though, please read the sticky threads, especially the one on Asking for Help. Posting your code properly is especially key in a python forum. Learn how to use the proper tags to post like this:
    Code:
    chest = {"trees" : "Gold beyond belief with gems and helms of gold is in the chest"}
    goblin = ["what dies but doesnt fall?", "trees"]
    print goblin[0]
    guess = raw_input("that is a riddle the goblin guarding the chest gave you, answer it to get to the chest:")
    if guess == goblin[1]:
    	print "yes, the answer to the riddle is the name of the key"
    	print "now call for key the and you can use it to open the chest"
    	print chest.get(guess, "you guessed the riddle?")
    else:
    	print "no"
    	print "\nPress enter to exit the dungeon and do back to the astle and spend you money"
    or like this
    python Code:
     
    chest = {"trees" : "Gold beyond belief with gems and helms of gold is in the chest"}
    goblin = ["what dies but doesnt fall?", "trees"]
    print goblin[0]
    guess = raw_input("that is a riddle the goblin guarding the chest gave you, answer it to get to the chest:")
    if guess == goblin[1]:
    	print "yes, the answer to the riddle is the name of the key"
    	print "now call for key the and you can use it to open the chest"
    	print chest.get(guess, "you guessed the riddle?")
    else:
    	print "no"
    	print "\nPress enter to exit the dungeon and do back to the astle and spend you money"
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    10
    yes i agree umm first off i might say your indenting is worng and this is what may be causing an error, but i kno this is not right because the trace would state that obviously. next time try to post correclty thank you
  12. #7
  13. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by Rc2001
    yes i agree umm first off i might say your indenting is worng and this is what may be causing an error, but i kno this is not right because the trace would state that obviously. next time try to post correclty thank you
    Well as long as you intent ( space ) once.. then that is correct... just wanted to say that

IMN logo majestic logo threadwatch logo seochat tools logo