Basic Problem with Code - Python 2.7.7

Basic Problem with Code - Python 2.7.7

Postby ElliotHeu » Thu Jun 26, 2014 7:29 pm

Hi,

I know this is probably a pretty basic problem but I am still fairly new to Python so I was wondering if you'd be able to help me out. I am making a simple text based game and I wanted to add a question within the 'else' section of an 'If Else' thing. I have imported time and random but whenever I run the program and try to answer the question it doesn't accept the correct answer. Any help is much appreciated thanks, here's the code:

correctanswerb = raw_input ("What has a face but no eyes, hands but no arms?\n")
while correctanswerb.lower() != "A clock":
print ("Nope, guess again\n")
correctanswerb = raw_input("Your guess: ")
print ("CORRECT!")

p.s: I can add more of the code if necessary, thanks
ElliotHeu
 
Posts: 1
Joined: Thu Jun 26, 2014 7:24 pm

Re: Basic Problem with Code - Python 2.7.7

Postby stranac » Thu Jun 26, 2014 7:35 pm

Hi, please read this to learn how to post code properly, and edit your post.
I would do it myself, but that indentation makes no sense.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1151
Joined: Thu Feb 07, 2013 3:42 pm

Re: Basic Problem with Code - Python 2.7.7

Postby Somelauw » Thu Jun 26, 2014 8:49 pm

Using my psychic powers I figured out how that code should be indented.
ElliotHeu wrote:Hi,
Code: Select all
        correctanswerb = raw_input ("What has a face but no eyes, hands but no arms?\n")
        while correctanswerb.lower() != "A clock":
            print ("Nope, guess again\n")
            correctanswerb = raw_input("Your guess: ")
        print ("CORRECT!")



However, next time please use code tags. The easier you make it for people to understand your code, the faster they'll help you.

Your problem is in this line:
Code: Select all
correctanswerb.lower() != "A clock":


You can probably find the problem yourself by putting this line somewhere in your while loop:
Code: Select all
print(repr(correctanswerb.lower()))


Unless it literally prints "A clock", your code isn't going to work.
Join the #python-forum IRC channel on irc.freenode.net!
Somelauw
 
Posts: 72
Joined: Tue Feb 12, 2013 8:30 pm


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests