0

How to calculate the sum of 2 dice?

My code: def myDiceSum(numberofside, numberofdice, thrown): for i in range(numberofside): t=[(rd.randint(1,numberofside)) for i in range(anzahlWuerfe)] For exampe: 1.iteration t=[1,4,3,1,5] 2.iteration t=[2,5,6,4,1] How can I add the elements of the 2 list with each other?

13th Oct 2019, 4:01 PM
Preet
4 Respuestas
0
Look into the zip() method - it should help you here.
13th Oct 2019, 4:27 PM
Russ
Russ - avatar
0
zip? no no no no...noooooooooooo. . use map() and a lambda.
13th Oct 2019, 5:13 PM
rodwynnejones
rodwynnejones - avatar
0
rodwynnejones Unless I've misunderstood the point of the question, I feel that using zip() results in some pretty succinct code (see below). How are you proposing that it should be done? https://code.sololearn.com/cfscCrd23U69/?ref=app
13th Oct 2019, 5:23 PM
Russ
Russ - avatar
0
This is what I had in mind:- t1 =[1, 4, 3, 1, 5] t2 =[2, 5, 6, 4, 1] t3 = list(map(lambda a, b: a + b, t1, t2)) print(list(t3)) ...but I see you method is more 'straight forward', nice way to do it (and handy to know).
13th Oct 2019, 5:31 PM
rodwynnejones
rodwynnejones - avatar