dimanche 9 avril 2017

Python Loop: 4 random numbers x 6

I want to have 6 times 4 dices with 6 sides (6 x 4d6) and Ive try to get a loop like:

    import random

print random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)
print random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)
print random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)
print random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)
print random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)
print random.randint(1, 6), random.randint(1, 6), random.randint(1, 6), random.randint(1, 6) code here

and I tried to do it like this:

import random
import tempfile
roll = 0
rzuty = [] #dicethrows
wynik = [] #result


for x in range(6):
    for y in range(4):
        roll = random.randint(1,6)
        rzuty.append(roll)
    rzuty.sort()
    rzuty.pop(0)

    for z in xrange(len(rzuty)):
        tempfile = rzuty

    wynik.append(tempfile)

    print (roll)

and I get only this out:

    1
    3
    3
    4
    6
    4

Process finished with exit code 0

I tried so many things but I cant find out whats wrong. Im just a beginner.




Aucun commentaire:

Enregistrer un commentaire