Prints a 2D list of the possible rolls of two dice in python -
i trying print 2d list of possible rolls of 2 dice in python 3.0+, using eclipse have 2 questions. first, why prof gave function take no arguments, should write main program? second, when runs r.append(result) , said attributeerror: 'int' object has no attribute 'append' can helps me please, thank functions:
def roll_two_dice(): """ ------------------------------------------------------- prints 2d list of possible rolls of 2 dice. ------------------------------------------------------- postconditions: prints table of possible dice rolls ------------------------------------------------------- """ r = [] rolls = [] r in range(dice1): c in range(dice2): result = r + c + 1 r.append(result) rolls.append(r) r = [] print("{}".format(rolls)) main program functions import roll_two_dice roll_two_dice()
the result should
table of 2 dice rolls
[[2 3 4 5 6 7] ............. [7 8 9 10 11 12]]
i not going homework, answer questions:
1) because professor wanted make assignment more challenging
2) because when trying append r
, r
int
for r in range(dice1): # r integers in range of 1st die c in range(dice2): result = r + c + 1 r.append(result) # trying append result said integer
think how name , rename variables change types throughout script.
Comments
Post a Comment