Claem
Claem

Reputation: 51

Reacting to raw input

I am trying to write a very simple dice-game program with Python, but am running into trouble with raw_input, as I've never used it before.

class hand(object):    
""""
Pull three dice from cup and hold
"""
def query(self):    
    question = raw_input('Would you like to roll?')
    if question == "yes"
        print "Let's roll"        

I want to eventually do much more advanced stuff with this; I can make a dice roll and get results but I'm trying to do it on command. I've spent hours researching raw input; most of the topics I find can shoot back a response but I need to be able to roll on command, within certain conditions. The other topics I find put things into an array, or can simply answer a question and that's all.

Whenever I run this I get invalid syntax. I had some other attempts as well; it would ask me the question but not respond at all when I typed 'yes'.

Upvotes: 0

Views: 117

Answers (2)

Carl Meyer
Carl Meyer

Reputation: 126581

Issues I notice in this code (none of which are related to raw_input):

  1. If query is meant to be a method of the hand class, the entire method should be indented.

  2. You need a colon after if question == "yes".

  3. answer would make more sense as a variable name than question, since the variable doesn't contain the question, it contains the user's answer.

  4. Usual Python style uses title-case for class names, so Hand, not hand.

Upvotes: 2

Philipp
Philipp

Reputation: 916

You forgot a colon if question == "yes": would be correct

Upvotes: 1

Related Questions