简体   繁体   中英

could not loop a random.randint and generate new numbers like a dice

this is my code I tried to loop the dice to generate new numbers every time like a dice using for but it didn't work please help me to make a code that would generate new numbers like a dice

import random

n=" "
for i in (n):
    dice=random.randint(0,6)
    print(a)

If you want one number everytime you run, just remove the for loop

import random

dice=random.randint(0,6)
print(dice)

If you want unlimited numbers, prefer using a while loop

import random

while True:
    dice=random.randint(0,6)
    print(dice)

If you want a specific number of roles, use a for loop with range

import random
for i in range(10):
    dice=random.randint(0,6)
    print(dice)
   

The only error I could see except for some useless lines was assigned the value to dice but printed a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM