[英]How to create a random list of numbers using a random.randint for loop?
[英]could not loop a random.randint and generate new numbers like a dice
這是我的代碼,我嘗試循環骰子以每次都像使用 for 的骰子一樣生成新數字,但它不起作用請幫助我制作一個可以像骰子一樣生成新數字的代碼
import random
n=" "
for i in (n):
dice=random.randint(0,6)
print(a)
如果您每次運行都想要一個數字,只需刪除 for 循環
import random
dice=random.randint(0,6)
print(dice)
如果你想要無限的數字,最好使用 while 循環
import random
while True:
dice=random.randint(0,6)
print(dice)
如果您想要特定數量的角色,請使用帶有范圍的 for 循環
import random
for i in range(10):
dice=random.randint(0,6)
print(dice)
除了一些無用的行之外,我能看到的唯一錯誤被賦值給 dice 但打印了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.