Hi and welcome.
No doubt there are a few different ways this could be done, such as using
I would use the
As an example, this will close every other door, as the second servant has been asked to do.
Caveat: this potential solution is simply my first thoughts and I'll have a think some more about if it's going to be practical or not.
To add: I think this could work, if you set up
I can't be more specific, without breaking the Forum rules; I'm close to doing that, as it is.
No doubt there are a few different ways this could be done, such as using
0
and 1
for the status of the cell doors. Then, you could use if door:
which would return True
or False
for 1
and 0
. That way, you don't need to code if door == 0:
, but I would go with a more literal approach and you may not have been introduced to constructing custom functions yet.I would use the
step
parameter of the range
function. Have you learned about that?As an example, this will close every other door, as the second servant has been asked to do.
door_open = "open" # door is open door_closed = "closed" # door is closed cell_doors = [door_open]*100 # open all the doors for door in range(1, 100, 2): # close every second door if cell_doors[door] == door_open: cell_doors[door] = door_closedThe above is where I would start from: it sets all the doors to 'open' and then closes every second door. Technically, you don't need the
if:
branch at this stage, because we know the status from the get-go, but I've put it in, for completeness.Caveat: this potential solution is simply my first thoughts and I'll have a think some more about if it's going to be practical or not.
To add: I think this could work, if you set up
servants = range(1, 101)
then nest for servant in servants:
with what I have above, using servant
as the 'step' parameter, and simply alternate each door (if it's closed, open; if it's open, close it). For that to work, start with all of the doors closed, not open, and 0
as the first door, not 1
.I can't be more specific, without breaking the Forum rules; I'm close to doing that, as it is.
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein