Reputation: 51
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
Reputation: 126581
Issues I notice in this code (none of which are related to raw_input
):
If query
is meant to be a method of the hand
class, the entire method should be indented.
You need a colon after if question == "yes"
.
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.
Usual Python style uses title-case for class names, so Hand
, not hand
.
Upvotes: 2