I tried to write a code to roll dice, code ends if the number is less than 6. But it continues if 6 comes, then continues if 6 comes then terminates if 6 comes or any other number(< 6) comes. But rather I get
6 again
6 again
6 again
like that, if 6 comes initially.
I am weak at nested loops and new at Python. The code is,
dice = np.random.randint(1,7)
i = 1
for i in range(1):
if (dice == 6):
print(dice, 'again')
continue
for i in range(1):
if (dice == 6):
print(dice, 'again')
continue
for i in range(1):
if (dice == 6):
print(dice, 'break')
else:
print(dice, 'over')
else:
print(dice, 'over')
i+=1
else:
print(dice, 'over')
break
I have few questions related to it:
- Issue is with
range
, how to tackle it? - Can we use nested for loops after
continue
? - Where to write I iteration?
Aucun commentaire:
Enregistrer un commentaire