cs102 lab6


http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/l6.html



Write a class in python to model an 8-sided dice. The dice has one number and one letter on each face, and each face is colored, as follows: {1/A/orange, 2/A/yellow, 3/A/green, 4/B/blue, 1/A/white, 2/B/black, 3/C/purple, 4/B/brown}. Write the following methods in your class:

  1. A fairToss() method that tosses the dice fairly.
  2. A getNumber() method that prints out the current number.
  3. A getLetter() method that prints out the current letter.
  4. A getColor() method that prints out the current color.
  5. A getDice() method that prints out all three parameters (this method can call the other methods getNumber, getLetter, getColor if you want).
  6. A getParity() method that returns EVEN if the number is even and ODD if it is odd.
  7. An unfairToss() method that gives twice as high a chance of getting black or white as a result, compared to getting any of the other colors (i.e. the probability for getting black or white is 0.2 each, and the probability for any other individual color is 0.1).
You should test your methods well (by calling them from the main program), to make sure they work as planned. You may use the DICE class covered in lectures as a starting point (see http://www.maths.nuigalway.ie/~gettrick/teach/cs102/progs/).
© NUI, Galway