Re: Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread bob gailer
# 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  using classes:
class Dice:
    ...
# no need for die1...die5 - use list comprehension:
alldice = [Dice(6) for i in range(5)]

# object is a bult-in type. it is inadvisable to assign to names of 
built-ins
# as this makes the built-in unavailable. Look up builtins (module) in 
help for

# a complete list.

# use list comprehension roll and report:
print([d.roll_dice() for d in alldice])

--
https://mail.python.org/mailman/listinfo/python-list


Re: Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread eliteanarchyracer
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/mailman/listinfo/python-list


Re: Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread Alister via Python-list
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 can use a loop:
> 
> for good_number in [2,3,4,6]:
>  if good_number in result:
>  print("you can roll again")
>  break
> else:
>  print("you have all 1's and 5's in your result")

or simply check for 1 & 5 to exit otherwise continue



-- 
Someone hooked the twisted pair wires into the answering machine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re : Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread armand.fouca...@telecom-bretagne.eu
   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

   -
   Armand FOUCAULT
   armand.fouca...@telecom-bretagne.eu

    Message original 
   Objet**: Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST
   De**: eliteanarchyra...@gmail.com
   : python-list@python.org
   Cc**:

 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 a
 result.
 if there is a 2,3,4 or 6 in the list i want to let the user roll again
 FOR EXACT LINE: PLEASE CHECK CODE

 CODE:

 from random import *

 class Dice:

 def __init__(self, sides, color="white"):
 self.sides = sides
 self.color = color

 def roll_dice(self):
 result = randint(1, self.sides)
 return result

 die1 = Dice(6)
 die2 = Dice(6)
 die3 = Dice(6)
 die4 = Dice(6)
 die5 = Dice(6)

 alldice = [die1, die2, die3, die4, die5]

 result = []

 start = input("Press enter to roll your dice:")

 for object in alldice:
 temp = object.roll_dice()
 result.append(temp)
 print(result)

 # - 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")
 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread Thomas Jollans

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 result:
print("you can roll again")
break
else:
print("you have all 1's and 5's in your result")
--
https://mail.python.org/mailman/listinfo/python-list


Re: Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread MRAB

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 a result.
if there is a 2,3,4 or 6 in the list i want to let the user roll again
FOR EXACT LINE: PLEASE CHECK CODE


CODE:


from random import *

class Dice:

 def __init__(self, sides, color="white"):
 self.sides = sides
 self.color = color

 def roll_dice(self):
 result = randint(1, self.sides)
 return result


die1 = Dice(6)
die2 = Dice(6)
die3 = Dice(6)
die4 = Dice(6)
die5 = Dice(6)

alldice = [die1, die2, die3, die4, die5]

result = []

start = input("Press enter to roll your dice:")

for object in alldice:
 temp = object.roll_dice()
 result.append(temp)
print(result)

# - 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")


The simplest (and longest) way is:

if 2 in result or 3 in result or 4 in result or 6 in result:

A cleverer way is to use sets:

if set(result) & {2, 3, 4, 6}:
--
https://mail.python.org/mailman/listinfo/python-list


Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

2018-10-06 Thread eliteanarchyracer
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 a result.
if there is a 2,3,4 or 6 in the list i want to let the user roll again
FOR EXACT LINE: PLEASE CHECK CODE


CODE: 


from random import *

class Dice:

def __init__(self, sides, color="white"):
self.sides = sides
self.color = color

def roll_dice(self):
result = randint(1, self.sides)
return result


die1 = Dice(6)
die2 = Dice(6)
die3 = Dice(6)
die4 = Dice(6)
die5 = Dice(6)

alldice = [die1, die2, die3, die4, die5]

result = []

start = input("Press enter to roll your dice:")

for object in alldice:
temp = object.roll_dice()
result.append(temp)
print(result)

# - 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")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Observations on the List - "Be More Kind"

2018-10-06 Thread Anthony Flury via Python-list

Bruce,

I completely agree; it is worth everyone remember that we are all here 
(even the moderators) as volunteers; we are here because either we want 
to ask questions, or we want to learn, or we want to help.


We do need to remember that the moderators is here to be nasty or 
because of a power trip - they are here to help, and they are volunteers.


Part of the really important thing about Python is the community and 
this list is a critical part of that community.; lets keep it that way 
please :-)


--
Anthony Flury
*Email* : anthony.fl...@btinternet.com 
*Twitter* : @TonyFlury 

On 05/10/18 11:22, Bruce Coram wrote:
I will declare at the outset, I am a lurker.  I don't know enough 
about Python to give advice that I could 100% guarantee would be helpful.


There have been two recent threads that summarise for me where the 
Python Mailing List has lost its way (and this started before Trump 
arrived as a new role model for how to treat your fellow man):


"Re: This thread is closed [an actual new thread]"

"Re: So apparently I've been banned from this list"

The level of vitriol and personal attacks on the moderators was 
profoundly disappointing, but not totally out of character for those 
who made the attacks.  There is no doubt that these people know 
software and Python and this certainly earns my respect,  but perhaps 
they need to retain a sense of perspective.  There are 7 billion 
people in the world.  There are plenty more people at least as good as 
you and many better, but they don't have the compelling urge to 
demonstrate their genius.  They get on with their work in a quiet 
professional manner.


Some humility in acknowledging that you stand on the shoulders of 
giants would not go amiss.  It might also reflect that you understand 
the good fortune that dealt you such a good hand in life.


You aren't always right, and you don't always have to insist on being 
right.  I found Steve D'Aprano always had to have the last word and 
had to prove he was right.  I found some of his posts to be 
intemperate in tone.


Why is there a need to score points with caustic remarks or throwaway 
comments?  Perhaps the person who posed his question should have read 
the documents, perhaps he should have searched the archives.  Tell 
them so politely and firmly.  If you cannot manage that then why say 
anything?  Not everyone who posts a poorly prepared question is idle 
and deserves a response that is less than polite.  Prepare a 
boilerplate standard reply that is polite for those questions that are 
easily resolved by the poster.


Perhaps the person who posts something you regard as nonsense is 
ignorant and lacks the knowledge they think they possess.  Instead of 
wasting your time with scholastic debate, put the time to good use 
improving your education in subjects you don't excel at.  I can 
guarantee the depth of your ignorance will be profound - there will be 
much for you to learn.  The effort some of you put in to the endless 
debates suggests that you have plenty of time on your hands - don't 
waste it.  It will be gone soon enough.


Don't waste time on the trolls, some of whom undoubtedly enjoy the 
ability to provoke a response.  Develop a greater sense of self 
awareness to enable you to recognise that you are being played. The 
intemperate tone of some of the exchanges damages the reputation of 
the List.


Life is hard enough without us adding to it.  Try silence as a response.

Listen to Frank Turner's latest album: "Be More Kind".   That is not a 
plug to buy the album, but the title seems apposite - and the music is 
good.


Regards

Bruce Coram


--
https://mail.python.org/mailman/listinfo/python-list


Re: Python indentation (3 spaces)

2018-10-06 Thread Chris Green
Terry Reedy  wrote:
> On 10/5/2018 4:48 PM, ts9...@gmail.com wrote:
> > I am new to Python programming but have significant SQL and C experience. 
> My simple question is,"Why not standardize Python indentations to 3 spaces 
> instead of 4 in order to avoid potential programming errors associated 
> with using "TAB" instead of 4 spaces?" 
> 
> IDLE (and other modern editors and IDEs) turns a typed TAB into a 
> user-settable n spaces, where n defaults to 4 (minimum 2, maximum 16).
> 
Other 'modern' editors? :-)  I use a vile clone (hardly modern) and
that gives me every possible option of what to do when a TAB is
entered. 

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to await multiple replies in arbitrary order (one coroutine per reply)?

2018-10-06 Thread Marko Rauhamaa
Russell Owen :
> I think what I'm looking for is a task-like thing I can create that I
> can end when *I* say it's time to end, and if I'm not quick enough
> then it will time out gracefully. But maybe there's a simpler way to
> do this. It doesn't seem like it should be difficult, but I'm stumped.
> Any advice would be appreciated.

I have experimented with similar questions in the past. FWIW, you can
see my small program here:

   http://pacujo.net/~marko/philosophers.py>


Occasionally, people post questions here about asyncio, but there are
few answers. I believe the reason is that asyncio hasn't broken through
as a very popular programming model even with Python enthusiasts.

I do a lot of network and system programming where event multiplexing is
essential. There are different paradigms to manage concurrency and
parallelism:

  * multithreading

  * multiprocessing

  * coroutines

  * callbacks from an event loop

Out of these, I prefer callbacks and processes and steer clear of
threads and coroutines. The reason is that in my (long) experience,

   Callbacks and processes make simple problems hard but manageable.
   Callbacks and processes make complex problems hard but manageable.

   Threads and coroutines make simple problems simple to solve.
   Threads and coroutines make complex problems humanly intractable.

Why is this? Threads and coroutines follow the same line of thinking.
They assume that concurrency involves a number linear state machines
("threads") that operate independently from each other. The "linear"
part means that in each blocking state, the thread is waiting for one
very definite event. When there are a number of possible events in each
state -- which there invariably are -- the multithreading model loses
its attractiveness.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list