My assignment is in Python 3.3.2 and it is here:
Create a class for a dice object that can randomly generate a number between 1 and 6 and save the file.
You will need the random module and
Create 2 Dice objects a and b and add their values together.
Here are the rules
Win = total equals 7 or 11
Lose = total equals 2,3 or 12
Roll again = total equals 5,6,8,9,10 until a 7 is rolled or the same number is thrown again.
Now the code I have written:
import random
class Dice:
'''A class that makes Dice'''
number = random.randint(1,6)
a = Dice
b = Dice
result = a.number + b.number
def resultgiver():
if result == '7':
result == '11'
print('You won! You got ' ,result,'.')
elif result == '2':
result == '3'
result == '12'
print('You lost! You got ' ,result,'.')
elif result == '5':
result == '6'
result == '8'
result == '9'
result == '10'
print('Roll again! You got ' ,result,'.')
elif result == '5':
result == '6'
result == '8'
result == '9'
result == '10'
elif result == '7':
result == '11'
resultgiver()