-1
(サイコロのロールが1と6の間の整数の乱数を取得することによってシミュレートすることができます)サイコロの10本のロールでリストを入力します。私は一種の持っているコード割り当ては、私が表示しなければならないと言う
Display all 10 rolls
Display all 10 rolls in backwards order
Display the first and last rolls
Display the sum of the rolls
Display the min and the max value rolled.
私は他の人に表示させる方法を理解できません。私はエラーコードを取得し続けます。ここで私はイライラになったので、私はこれまでのところ、私はそれのビットを削除したものです:
import random
def roll(sides=6):
numRolled = random.randint(1,sides)
return num_rolled
def rollDice():
sides = 6
rolling = True
diceList=[]
while rolling:
numRolled = random.randint(1,sides)
diceList.append(numRolled)
print (numRolled, end="")
if len(diceList) == 10:
rolling = False
return diceList
def main():
print (rollDice())
print (diceList)
print (rolldice.sort())
print (rollDice[0],rolldice[9])
print (rolldice.min,rolldice.max)
print (rolldice.sum)
main()
あなたは決して関数の出力をどの変数にも割り当てません。関数内で特に定義されている 'diceList'は、直接外部にアクセスすることはできません。なぜなら、' rolldice'変数 –