试图选择骰子和侧面

时间:2017-03-28 21:09:20

标签: python

我正在尝试生成能够拥有多个骰子然后选择骰子上的边数这是我的代码我将如何使这项工作

print("\n") #Creates new program
print("Welcome...")
print("You are are playing a game of dice, this is a two player game, who  ever rolls the highest number wins")
name1 = input("What is Player 1's Name?") #Inputs "player 1's" name 
print("Hello", name1)
name2 = input("What is Player 2's Name?")
print("Greetings",name2)
from random import randint
Dice = input("Please select number of dice you would like to use (atleast 1)")
Sides = input("Please select number of sides on dice you would like to use")
print("You have selected", Dice," dice and", Sides,"Sides")
Roll11 = int(randint(Dice,Sides))
Roll12 = int(randint(Dice,Sides))
print ("Player 1's Roll")
print(Roll11)
print ("Player 2's Roll")
print (Roll12)

2 个答案:

答案 0 :(得分:1)

试试这个:

   print("Welcome...")
    print("You are are playing a game of dice, this is a two player game, who  ever rolls the highest number wins")
    name1 = input("What is Player 1's Name?") #Inputs "player 1's" name 
    print("Hello", name1)
    name2 = input("What is Player 2's Name?")
    print("Greetings",name2)
    from random import randint
    Dice = int(input("Please select number of dice you would like to use (atleast 1)"))
    Sides = int(input("Please select number of sides on dice you would like to use"))
    print("You have selected", Dice," dice and", Sides,"Sides")
    Roll1=0
    Roll2=0
    for i in range(Dice):
        Roll1 += randint(1,Sides)
        Roll2 += randint(1,Sides)
    print ("Player 1's Roll")
    print(Roll1)
    print ("Player 2's Roll")
    print (Roll2)

更改:首先,代码中不需要第一行。其次,您将int应用于错误的行。 randint会返回int,但input会返回string。第三,您在DiceSides之间生成了一个随机数。我修改为生成1到Dice

之间的Sides个随机数

答案 1 :(得分:0)

问题,我可以看到,是这一行:

Roll11 = int(randint(Dice,Sides))

您正尝试将字符串值作为整数参数传递。

尝试像这样使用它:

Roll11 = randint(int(Dice), int(Sides))