如何编写骰子游戏添加两个玩家名称

时间:2021-04-19 09:51:52

标签: python

import random

class Dice:
  def roll(self):
    First = random.randit(1, 6)
    Second = random.randint(1, 6)
    return First, second


dice1= Dice()
dice1.roll()

1 个答案:

答案 0 :(得分:0)

您没有很好地描述您在这里尝试做什么,但根据我的假设,您可能需要这样的东西:

import random

class Player:
  # initialize a player class with name of player
  def __init__(self, name):
    this.name = name

  # Roll dice method
  def roll(self):
    First = random.randit(1, 6)
    Second = random.randint(1, 6)
    return First, second


player1 = Player("Alice")
player1.roll()
player2 = Player("John")
player2.roll()