Lomore - 4 months ago 21

Python Question

I'm trying to make a dice tosser for my nephew so he can play boardgames without dice. i have got stuck in a while loop if even if i enter a condition that is true. I'm trying to get him to select which dice he wants to use but if he selects a wrong dice then it asks him to enter it again. my code is ...

`dice_select = input('Enter the amount of sides are on the dice you want to throw, either 4, 6, or 12: ')`

while dice_select != 4 or dice_select != 6 or dice_select != 12:

dice_select = int(input('Sorry thats not quite right. Enter the amount of sides are on the dice you want to throw, either 4, 6, or 12: '))

if i enter 4, 6 or 12 then it still puts me into the loop when it is supposed to continue.

Answer

Try This:

```
dice_select = int(input('Enter the amount of sides are on the dice you want to throw, either 4, 6, or 12: '))
while not (dice_select == 4 or dice_select == 6 or dice_select == 12):
dice_select = int(input('Sorry thats not quite right. Enter the amount of sides are on the dice you want to throw, either 4, 6, or 12: '))
```

This means loop until dice_select equals 4, 6 or 12.

With your program, your while loop condition is always true, because when it equals 4, your program is checking false or true or true which will always be true.

In other words your program is looking for when dice_select equals 4,6 and 12 at the same time. Which is not possible.