May-13-2019, 05:57 AM
(This post was last modified: May-13-2019, 06:05 AM by sunny_awesome.)
Problem statement :
Dice: The module random contains functions that generate random numbers in a variety of ways.
The function randint() returns an integer in the range you provide. The following code returns a number between 1 and 6:
from random import randint
x = randint(1, 6)
Make a class Die with one attribute called sides, which has a default value of 6.
Write a method called roll_die() that prints a random number between 1 and the number of sides the die has.
Make a 6-sided die and roll it 10 times.Make a 10-sided die and a 20-sided die. Roll each die 10 times.
My try:
Dice: The module random contains functions that generate random numbers in a variety of ways.
The function randint() returns an integer in the range you provide. The following code returns a number between 1 and 6:
from random import randint
x = randint(1, 6)
Make a class Die with one attribute called sides, which has a default value of 6.
Write a method called roll_die() that prints a random number between 1 and the number of sides the die has.
Make a 6-sided die and roll it 10 times.Make a 10-sided die and a 20-sided die. Roll each die 10 times.
My try:
from random import randint class Dice(object): def __init__(self): self.sides=6 def roll_dice(self): x=randint(1,self.sides) print(x) dice_roll1=Dice() dice_roll1.roll_dice(10)I'm getting this error:
Error:Traceback (most recent call last):
File "main.py", line 19, in <module>
dice_roll1.roll_dice(10)
TypeError: roll_dice() takes 1 positional argument but 2 were given
Please help me clear this error