*if any(roll != 1 and roll != 5 for roll in result):*
another extract of py's beauty!
Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ
Mauritius
--
https://mail.python.org/mailman/listinfo/python-list
On 2018-10-06, eliteanarchyra...@gmail.com
wrote:
> Hi, I am new to python and would like someones help on the
> following:
>
> After rolling 5 dice and putting the results into a list, I
> need to check if any dice is not a 1 or 5.
if any(roll != 1 and roll != 5 for roll in result):
> # - T
# your program is quite complicated. classes are overkill. A simpler
solution is:
import random
for i in range(5):
roll = random.randint(1,6)
if roll not in (1,5):
print('you can roll again')
break
else:
print("you have all 1's and 5's in your result'")
# comments on
Well these worked like a charm. Cant say I understand some of them and will
have to look into utilizing them in the future, but I appreciate everyones
responses and thank you all. Never needed to check for multiple instances in a
list before.
Nice to have help!
--
https://mail.python.org/mailm
On Sat, 06 Oct 2018 21:56:09 +0200, Thomas Jollans wrote:
> On 06/10/2018 20:10, eliteanarchyra...@gmail.com wrote:
>> # - THIS LINE IS WHERE I NEED HELP # ( if 2, 3, 4, 6 in list:
>> )
>> print("you can roll again")
>> else:
>> print("you have all 1's and 5's in your result")
>
You could use any and a generator expression.
It sounds pretty hard, but it's actually easily expressed, and pretty
intelligible.
Here you go:
if any(n in result for n in [2, 3, 4, 6]):
# reroll
else:
# do your thing
-
Arma
On 06/10/2018 20:10, eliteanarchyra...@gmail.com wrote:
# - THIS LINE IS WHERE I NEED HELP # ( if 2, 3, 4, 6 in list: )
print("you can roll again")
else:
print("you have all 1's and 5's in your result")
You can use a loop:
for good_number in [2,3,4,6]:
if good_number in
On 2018-10-06 19:10, eliteanarchyra...@gmail.com wrote:
Hi, I am new to python and would like someones help on the following:
After rolling 5 dice and putting the results into a list, I need to check if
any dice is not a 1 or 5.
if all dice in the list are either a 1 or 5 , I want to calculate