我试图生成能够有一个骰子数,然后选择骰子上的边数这是我的代码我该如何使这一工作
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)
试试这个:
更改:首先,代码中不需要第一行。其次,您将
int
应用于错误的行。randint
返回int
,但input
返回string
。第三,在Dice
和Sides
之间生成一个随机数。我修改为在1和Sides
之间生成Dice
随机数我知道,问题是这条线:
您正在尝试将字符串值作为整数参数传递。你知道吗
试着这样使用:
相关问题 更多 >
编程相关推荐