Because indentation matters and return ...
leaves the function you are in.
Remove the indentation of your for loop so it belongs to your main code and not into your function )where it never would be executed because after return
).
Also change for i in range (1, num_roll):
to for i in range (1, num_roll+1):
- the upper limit of range
is exclusive so range(1,4)
will give you 1,2,3:
import random
num_roll_str = input('How many time you want to roll the dice? ')
num_roll = int(num_roll_str)
def roll_2_dice():
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
return dice1, dice2 # return is THE END, noting happens after it
for i in range (1, num_roll+1):
d1, d2 = roll_2_dice() # call your function and print it
print('{0:>10}{1:>10}{2:>10}'.format(i, d1, d2))
I fixed the indentation to 4 spaces, see pep 008 guideline
Doku:
Output for 5:
1 5 5
2 1 2
3 3 2
4 2 6
5 6 4