Couple of problems:
- you need parentheses around your class instances:
a = Dice()
and
b = Dice()
result
is an integer yet all your if statments check if it equals a char. remove all the quotes around your the numbersif result == 5:
you need an init in your class so you always get a different number when you instantiate the class.
class Dice: '''A class that makes Dice'''
def __init__(self): self.number = random.randint(1,6)
try putting a else at the end to catch any result that is not 7 or 5:
elif result == '7':
result == '11'
else:
print "we got here"
I think you are trying to emulate a switch statement with your if statement. The way you did wont work but try this:
def resultgiver():
if result in [7,11]:
print('You won! You got ' ,result,'.')
elif result in [2, 3, 12]:
print('You lost! You got ' ,result,'.')
elif result in [5, 6, 8, 9, 10]:
print('Roll again! You got ' ,result,'.')
else:
print "default case for result =", result