Computer Science, asked by TheBrainyme, 4 months ago

A game of throwing dice is played between two players. Each player throws a dice unless his/her score adds up to 20. The player getting score 20 in the minimum number of throws is declared the winner. Define a class Game with the following specifications:

Data Members: Name, player number

Member methods:

i) To accept the details of the player

ii) To compute the number of tries by each player to get score 20

iii) To display the result

Write a main method to create an object of a class and call the above member methods.​

Answers

Answered by varadanrajan5179
0

Python program for an automatic rolling dice game.

Note: Due to some issues, we have placed ^ in place of the letter 'n' in the ra^dint. Please replace all the ^ with the letter 'n' in this program. Thank you!

Program:

import random

p1=0

p2=0

while(p1<20 and p2<20):

  a=random.ra^dint(1,6)

  print("Player A rolling dice... The value is",a)

  p1=p1+a

  b=random.ra^dint(1,6)

  print("Player B rolling dice... The value is",b)

  p2=p2+b

  if p1>=20 and p2>=20:

      print("Match draw!")

      break

  elif p1>=20:

      print("The winner is Player A")

      break

  elif p2>=20:

      print("The winner is Player B")

      break

Output:

Player A rolling dice... The value is 6

Player B rolling dice... The value is 2

Player A rolling dice... The value is 6

Player B rolling dice... The value is 2

Player A rolling dice... The value is 3

Player B rolling dice... The value is 2

Player A rolling dice... The value is 3

Player B rolling dice... The value is 4

Player A rolling dice... The value is 2

Player B rolling dice... The value is 1

The winner is Player A

Similar questions