Python Monty hall n number of doors
I have a model of the Monty Hall program running but I need to figure out how to ask the user for the number of doors of in this case, hiding places. The code for the simulation works, it's just the starting section I need help with. This is what I have so far, thanks for any help in advance.
import random
#Ask the user for how many runs to simumlate
runs = int(input("How many games do you want to simulate?"))
switchwins, nonswitchwins, switchlosses, nonswitchlosses = 0, 0, 0, 0
# Get the random number started with a seed
random.seed()
#run once for user switching and once for user not switching
for swap in True,False:
# Do everything for the number of runs we have
for i in range(runs):
#Ask the user for the number of hiding places which must be greater than 3
while True:
hidingplaces = int(input("This game requires 3 or more hiding places. How many would you like?"))
if hidingplaces < 3:
#return error
raise ValueError(f'doors must be greater than three, not {hidingplaces}')
else:
break
# All prizes are nothing apart from one which holds the coin
prizes = ['nothing', 'nothing', 'coin']
# Randomly mix them up
random.shuffle(prizes)
#select a random location
ChoiceA = random.randrange(hidingplaces)
# print("Before the prize is revealed, I will show you what is in one of the other hiding places")
# remove one of the other hiding places which has nothing as a prize and isn't ChoiceA
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and contents == "nothing":
showlocation = currentlocation
# print("There is nothing in this location", showlocation)
break
if swap:
#swap to the other location
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and currentlocation != showlocation:
swap_to = currentlocation
# check if the swapped choice is a win
if prizes[swap_to] == "coin":
switchwins +=1
else:
switchlosses +=1
# when not swapping locations check for win
else:
if prizes[ChoiceA] == "coin":
nonswitchwins +=1
else:
nonswitchlosses +=1
print("This is the number of wins if the user switched", round((switchwins/runs)*100,1), "%")
print("This is the number of wins if the user didn't switch", round((nonswitchwins/runs)*100,1),"%")
The error I'm getting is:
IndexError Traceback (most recent call last)
<ipython-input-15-e7e700a3b515> in <module>()
57 # when not swapping locations check for win
58 else:
---> 59 if prizes[ChoiceA] == "coin":
60 nonswitchwins +=1
61 else:
IndexError: list index out of range
python python-3.x
add a comment |
I have a model of the Monty Hall program running but I need to figure out how to ask the user for the number of doors of in this case, hiding places. The code for the simulation works, it's just the starting section I need help with. This is what I have so far, thanks for any help in advance.
import random
#Ask the user for how many runs to simumlate
runs = int(input("How many games do you want to simulate?"))
switchwins, nonswitchwins, switchlosses, nonswitchlosses = 0, 0, 0, 0
# Get the random number started with a seed
random.seed()
#run once for user switching and once for user not switching
for swap in True,False:
# Do everything for the number of runs we have
for i in range(runs):
#Ask the user for the number of hiding places which must be greater than 3
while True:
hidingplaces = int(input("This game requires 3 or more hiding places. How many would you like?"))
if hidingplaces < 3:
#return error
raise ValueError(f'doors must be greater than three, not {hidingplaces}')
else:
break
# All prizes are nothing apart from one which holds the coin
prizes = ['nothing', 'nothing', 'coin']
# Randomly mix them up
random.shuffle(prizes)
#select a random location
ChoiceA = random.randrange(hidingplaces)
# print("Before the prize is revealed, I will show you what is in one of the other hiding places")
# remove one of the other hiding places which has nothing as a prize and isn't ChoiceA
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and contents == "nothing":
showlocation = currentlocation
# print("There is nothing in this location", showlocation)
break
if swap:
#swap to the other location
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and currentlocation != showlocation:
swap_to = currentlocation
# check if the swapped choice is a win
if prizes[swap_to] == "coin":
switchwins +=1
else:
switchlosses +=1
# when not swapping locations check for win
else:
if prizes[ChoiceA] == "coin":
nonswitchwins +=1
else:
nonswitchlosses +=1
print("This is the number of wins if the user switched", round((switchwins/runs)*100,1), "%")
print("This is the number of wins if the user didn't switch", round((nonswitchwins/runs)*100,1),"%")
The error I'm getting is:
IndexError Traceback (most recent call last)
<ipython-input-15-e7e700a3b515> in <module>()
57 # when not swapping locations check for win
58 else:
---> 59 if prizes[ChoiceA] == "coin":
60 nonswitchwins +=1
61 else:
IndexError: list index out of range
python python-3.x
It's unclear what you're asking for. Your code runs and behaves fine to me.
– Daniel R. Livingston
Nov 19 '18 at 18:55
Posted the whole code now :)
– user10676306
Nov 19 '18 at 19:01
Can you post the error you're getting as well, and/or the expected behavior vs. the actual behavior? I.e., what exactly is going wrong, and where, and what should it be doing instead?
– Daniel R. Livingston
Nov 19 '18 at 19:04
Edited the error message in
– user10676306
Nov 19 '18 at 19:08
I fixed your second issue. Check my answer. If it fixed it, don't forget to click the checkmark.
– Trooper Z
Nov 19 '18 at 19:29
add a comment |
I have a model of the Monty Hall program running but I need to figure out how to ask the user for the number of doors of in this case, hiding places. The code for the simulation works, it's just the starting section I need help with. This is what I have so far, thanks for any help in advance.
import random
#Ask the user for how many runs to simumlate
runs = int(input("How many games do you want to simulate?"))
switchwins, nonswitchwins, switchlosses, nonswitchlosses = 0, 0, 0, 0
# Get the random number started with a seed
random.seed()
#run once for user switching and once for user not switching
for swap in True,False:
# Do everything for the number of runs we have
for i in range(runs):
#Ask the user for the number of hiding places which must be greater than 3
while True:
hidingplaces = int(input("This game requires 3 or more hiding places. How many would you like?"))
if hidingplaces < 3:
#return error
raise ValueError(f'doors must be greater than three, not {hidingplaces}')
else:
break
# All prizes are nothing apart from one which holds the coin
prizes = ['nothing', 'nothing', 'coin']
# Randomly mix them up
random.shuffle(prizes)
#select a random location
ChoiceA = random.randrange(hidingplaces)
# print("Before the prize is revealed, I will show you what is in one of the other hiding places")
# remove one of the other hiding places which has nothing as a prize and isn't ChoiceA
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and contents == "nothing":
showlocation = currentlocation
# print("There is nothing in this location", showlocation)
break
if swap:
#swap to the other location
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and currentlocation != showlocation:
swap_to = currentlocation
# check if the swapped choice is a win
if prizes[swap_to] == "coin":
switchwins +=1
else:
switchlosses +=1
# when not swapping locations check for win
else:
if prizes[ChoiceA] == "coin":
nonswitchwins +=1
else:
nonswitchlosses +=1
print("This is the number of wins if the user switched", round((switchwins/runs)*100,1), "%")
print("This is the number of wins if the user didn't switch", round((nonswitchwins/runs)*100,1),"%")
The error I'm getting is:
IndexError Traceback (most recent call last)
<ipython-input-15-e7e700a3b515> in <module>()
57 # when not swapping locations check for win
58 else:
---> 59 if prizes[ChoiceA] == "coin":
60 nonswitchwins +=1
61 else:
IndexError: list index out of range
python python-3.x
I have a model of the Monty Hall program running but I need to figure out how to ask the user for the number of doors of in this case, hiding places. The code for the simulation works, it's just the starting section I need help with. This is what I have so far, thanks for any help in advance.
import random
#Ask the user for how many runs to simumlate
runs = int(input("How many games do you want to simulate?"))
switchwins, nonswitchwins, switchlosses, nonswitchlosses = 0, 0, 0, 0
# Get the random number started with a seed
random.seed()
#run once for user switching and once for user not switching
for swap in True,False:
# Do everything for the number of runs we have
for i in range(runs):
#Ask the user for the number of hiding places which must be greater than 3
while True:
hidingplaces = int(input("This game requires 3 or more hiding places. How many would you like?"))
if hidingplaces < 3:
#return error
raise ValueError(f'doors must be greater than three, not {hidingplaces}')
else:
break
# All prizes are nothing apart from one which holds the coin
prizes = ['nothing', 'nothing', 'coin']
# Randomly mix them up
random.shuffle(prizes)
#select a random location
ChoiceA = random.randrange(hidingplaces)
# print("Before the prize is revealed, I will show you what is in one of the other hiding places")
# remove one of the other hiding places which has nothing as a prize and isn't ChoiceA
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and contents == "nothing":
showlocation = currentlocation
# print("There is nothing in this location", showlocation)
break
if swap:
#swap to the other location
for currentlocation, contents in enumerate(prizes):
if currentlocation != ChoiceA and currentlocation != showlocation:
swap_to = currentlocation
# check if the swapped choice is a win
if prizes[swap_to] == "coin":
switchwins +=1
else:
switchlosses +=1
# when not swapping locations check for win
else:
if prizes[ChoiceA] == "coin":
nonswitchwins +=1
else:
nonswitchlosses +=1
print("This is the number of wins if the user switched", round((switchwins/runs)*100,1), "%")
print("This is the number of wins if the user didn't switch", round((nonswitchwins/runs)*100,1),"%")
The error I'm getting is:
IndexError Traceback (most recent call last)
<ipython-input-15-e7e700a3b515> in <module>()
57 # when not swapping locations check for win
58 else:
---> 59 if prizes[ChoiceA] == "coin":
60 nonswitchwins +=1
61 else:
IndexError: list index out of range
python python-3.x
python python-3.x
edited Nov 19 '18 at 20:15


Trooper Z
765424
765424
asked Nov 19 '18 at 18:13
user10676306
It's unclear what you're asking for. Your code runs and behaves fine to me.
– Daniel R. Livingston
Nov 19 '18 at 18:55
Posted the whole code now :)
– user10676306
Nov 19 '18 at 19:01
Can you post the error you're getting as well, and/or the expected behavior vs. the actual behavior? I.e., what exactly is going wrong, and where, and what should it be doing instead?
– Daniel R. Livingston
Nov 19 '18 at 19:04
Edited the error message in
– user10676306
Nov 19 '18 at 19:08
I fixed your second issue. Check my answer. If it fixed it, don't forget to click the checkmark.
– Trooper Z
Nov 19 '18 at 19:29
add a comment |
It's unclear what you're asking for. Your code runs and behaves fine to me.
– Daniel R. Livingston
Nov 19 '18 at 18:55
Posted the whole code now :)
– user10676306
Nov 19 '18 at 19:01
Can you post the error you're getting as well, and/or the expected behavior vs. the actual behavior? I.e., what exactly is going wrong, and where, and what should it be doing instead?
– Daniel R. Livingston
Nov 19 '18 at 19:04
Edited the error message in
– user10676306
Nov 19 '18 at 19:08
I fixed your second issue. Check my answer. If it fixed it, don't forget to click the checkmark.
– Trooper Z
Nov 19 '18 at 19:29
It's unclear what you're asking for. Your code runs and behaves fine to me.
– Daniel R. Livingston
Nov 19 '18 at 18:55
It's unclear what you're asking for. Your code runs and behaves fine to me.
– Daniel R. Livingston
Nov 19 '18 at 18:55
Posted the whole code now :)
– user10676306
Nov 19 '18 at 19:01
Posted the whole code now :)
– user10676306
Nov 19 '18 at 19:01
Can you post the error you're getting as well, and/or the expected behavior vs. the actual behavior? I.e., what exactly is going wrong, and where, and what should it be doing instead?
– Daniel R. Livingston
Nov 19 '18 at 19:04
Can you post the error you're getting as well, and/or the expected behavior vs. the actual behavior? I.e., what exactly is going wrong, and where, and what should it be doing instead?
– Daniel R. Livingston
Nov 19 '18 at 19:04
Edited the error message in
– user10676306
Nov 19 '18 at 19:08
Edited the error message in
– user10676306
Nov 19 '18 at 19:08
I fixed your second issue. Check my answer. If it fixed it, don't forget to click the checkmark.
– Trooper Z
Nov 19 '18 at 19:29
I fixed your second issue. Check my answer. If it fixed it, don't forget to click the checkmark.
– Trooper Z
Nov 19 '18 at 19:29
add a comment |
2 Answers
2
active
oldest
votes
The problem you're reporting is not, after all, with the user input routine. It is that you are allowing the user to specify hidingplaces
> 3 while at the same time hardcoding the list prizes
to have exactly 3 entries. ChoiceA
, which can be (randomly) set to any number less than hidingplaces
, is used as an index into prizes
. It raises the exception you report whenever ChoiceA
happens to be greater than 2.
Strategies to fix this might include (a) making use of the value of hidingplaces
when you define the list of prizes
or (b) using ChoiceA % len(prizes)
as the index into prizes
instead of just ChoiceA
. Note that these have different effects on the statistical behavior of the simulation: the correct choice depends on how you want it to behave. From the comment next to your existing definition of prizes
, this definition is probably what you intend:
prizes = [ 'coin' ] + [ 'nothing' ] * ( hidingplaces - 1 )
add a comment |
I have fixed your code. I rewrote it and simplified it, fixed some syntax errors, and fixed some indent errors.
Check the comments in the code.
EDIT: I have fixed the code.
def askDoors():
'''
Ask the user for the number of hiding places which must be greater than 3
'''
return int(input("This game requires 3 or more hiding places. How many would you like?"))
hidingplaces = askDoors()
while hidingplaces < 3:
# return error
print('Doors must be greater than three, not %d.' % hidingplaces)
hidingplaces = askDoors()
print('Start.') # put game here (recommended to use a function)
EDIT: For the second problem, just change prizes to prizes = ['coin']
and add this right after it.
for i in range(hidingplaces):
prizes.append('nothing')
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
you are usinghidingplaces
as a global and as a local variable. and your functionaskDoors()
is not returning anything. that's not a good practice... and also not answering the question...
– George Bou
Nov 19 '18 at 18:54
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380442%2fpython-monty-hall-n-number-of-doors%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem you're reporting is not, after all, with the user input routine. It is that you are allowing the user to specify hidingplaces
> 3 while at the same time hardcoding the list prizes
to have exactly 3 entries. ChoiceA
, which can be (randomly) set to any number less than hidingplaces
, is used as an index into prizes
. It raises the exception you report whenever ChoiceA
happens to be greater than 2.
Strategies to fix this might include (a) making use of the value of hidingplaces
when you define the list of prizes
or (b) using ChoiceA % len(prizes)
as the index into prizes
instead of just ChoiceA
. Note that these have different effects on the statistical behavior of the simulation: the correct choice depends on how you want it to behave. From the comment next to your existing definition of prizes
, this definition is probably what you intend:
prizes = [ 'coin' ] + [ 'nothing' ] * ( hidingplaces - 1 )
add a comment |
The problem you're reporting is not, after all, with the user input routine. It is that you are allowing the user to specify hidingplaces
> 3 while at the same time hardcoding the list prizes
to have exactly 3 entries. ChoiceA
, which can be (randomly) set to any number less than hidingplaces
, is used as an index into prizes
. It raises the exception you report whenever ChoiceA
happens to be greater than 2.
Strategies to fix this might include (a) making use of the value of hidingplaces
when you define the list of prizes
or (b) using ChoiceA % len(prizes)
as the index into prizes
instead of just ChoiceA
. Note that these have different effects on the statistical behavior of the simulation: the correct choice depends on how you want it to behave. From the comment next to your existing definition of prizes
, this definition is probably what you intend:
prizes = [ 'coin' ] + [ 'nothing' ] * ( hidingplaces - 1 )
add a comment |
The problem you're reporting is not, after all, with the user input routine. It is that you are allowing the user to specify hidingplaces
> 3 while at the same time hardcoding the list prizes
to have exactly 3 entries. ChoiceA
, which can be (randomly) set to any number less than hidingplaces
, is used as an index into prizes
. It raises the exception you report whenever ChoiceA
happens to be greater than 2.
Strategies to fix this might include (a) making use of the value of hidingplaces
when you define the list of prizes
or (b) using ChoiceA % len(prizes)
as the index into prizes
instead of just ChoiceA
. Note that these have different effects on the statistical behavior of the simulation: the correct choice depends on how you want it to behave. From the comment next to your existing definition of prizes
, this definition is probably what you intend:
prizes = [ 'coin' ] + [ 'nothing' ] * ( hidingplaces - 1 )
The problem you're reporting is not, after all, with the user input routine. It is that you are allowing the user to specify hidingplaces
> 3 while at the same time hardcoding the list prizes
to have exactly 3 entries. ChoiceA
, which can be (randomly) set to any number less than hidingplaces
, is used as an index into prizes
. It raises the exception you report whenever ChoiceA
happens to be greater than 2.
Strategies to fix this might include (a) making use of the value of hidingplaces
when you define the list of prizes
or (b) using ChoiceA % len(prizes)
as the index into prizes
instead of just ChoiceA
. Note that these have different effects on the statistical behavior of the simulation: the correct choice depends on how you want it to behave. From the comment next to your existing definition of prizes
, this definition is probably what you intend:
prizes = [ 'coin' ] + [ 'nothing' ] * ( hidingplaces - 1 )
edited Nov 19 '18 at 20:30
answered Nov 19 '18 at 20:23
jezjez
7,7461942
7,7461942
add a comment |
add a comment |
I have fixed your code. I rewrote it and simplified it, fixed some syntax errors, and fixed some indent errors.
Check the comments in the code.
EDIT: I have fixed the code.
def askDoors():
'''
Ask the user for the number of hiding places which must be greater than 3
'''
return int(input("This game requires 3 or more hiding places. How many would you like?"))
hidingplaces = askDoors()
while hidingplaces < 3:
# return error
print('Doors must be greater than three, not %d.' % hidingplaces)
hidingplaces = askDoors()
print('Start.') # put game here (recommended to use a function)
EDIT: For the second problem, just change prizes to prizes = ['coin']
and add this right after it.
for i in range(hidingplaces):
prizes.append('nothing')
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
you are usinghidingplaces
as a global and as a local variable. and your functionaskDoors()
is not returning anything. that's not a good practice... and also not answering the question...
– George Bou
Nov 19 '18 at 18:54
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
add a comment |
I have fixed your code. I rewrote it and simplified it, fixed some syntax errors, and fixed some indent errors.
Check the comments in the code.
EDIT: I have fixed the code.
def askDoors():
'''
Ask the user for the number of hiding places which must be greater than 3
'''
return int(input("This game requires 3 or more hiding places. How many would you like?"))
hidingplaces = askDoors()
while hidingplaces < 3:
# return error
print('Doors must be greater than three, not %d.' % hidingplaces)
hidingplaces = askDoors()
print('Start.') # put game here (recommended to use a function)
EDIT: For the second problem, just change prizes to prizes = ['coin']
and add this right after it.
for i in range(hidingplaces):
prizes.append('nothing')
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
you are usinghidingplaces
as a global and as a local variable. and your functionaskDoors()
is not returning anything. that's not a good practice... and also not answering the question...
– George Bou
Nov 19 '18 at 18:54
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
add a comment |
I have fixed your code. I rewrote it and simplified it, fixed some syntax errors, and fixed some indent errors.
Check the comments in the code.
EDIT: I have fixed the code.
def askDoors():
'''
Ask the user for the number of hiding places which must be greater than 3
'''
return int(input("This game requires 3 or more hiding places. How many would you like?"))
hidingplaces = askDoors()
while hidingplaces < 3:
# return error
print('Doors must be greater than three, not %d.' % hidingplaces)
hidingplaces = askDoors()
print('Start.') # put game here (recommended to use a function)
EDIT: For the second problem, just change prizes to prizes = ['coin']
and add this right after it.
for i in range(hidingplaces):
prizes.append('nothing')
I have fixed your code. I rewrote it and simplified it, fixed some syntax errors, and fixed some indent errors.
Check the comments in the code.
EDIT: I have fixed the code.
def askDoors():
'''
Ask the user for the number of hiding places which must be greater than 3
'''
return int(input("This game requires 3 or more hiding places. How many would you like?"))
hidingplaces = askDoors()
while hidingplaces < 3:
# return error
print('Doors must be greater than three, not %d.' % hidingplaces)
hidingplaces = askDoors()
print('Start.') # put game here (recommended to use a function)
EDIT: For the second problem, just change prizes to prizes = ['coin']
and add this right after it.
for i in range(hidingplaces):
prizes.append('nothing')
edited Nov 19 '18 at 19:28
answered Nov 19 '18 at 18:25


Trooper ZTrooper Z
765424
765424
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
you are usinghidingplaces
as a global and as a local variable. and your functionaskDoors()
is not returning anything. that's not a good practice... and also not answering the question...
– George Bou
Nov 19 '18 at 18:54
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
add a comment |
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
you are usinghidingplaces
as a global and as a local variable. and your functionaskDoors()
is not returning anything. that's not a good practice... and also not answering the question...
– George Bou
Nov 19 '18 at 18:54
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
Tried your code (thank you!) but it returned an error, if edited mine slightly but it keeps coming up with the error "list index out of range"
– user10676306
Nov 19 '18 at 18:47
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
@Billygem08 Put my code in a separate file, and run it. It should work. The "list index out of range' error might be in the other code.
– Trooper Z
Nov 19 '18 at 18:48
you are using
hidingplaces
as a global and as a local variable. and your function askDoors()
is not returning anything. that's not a good practice... and also not answering the question...– George Bou
Nov 19 '18 at 18:54
you are using
hidingplaces
as a global and as a local variable. and your function askDoors()
is not returning anything. that's not a good practice... and also not answering the question...– George Bou
Nov 19 '18 at 18:54
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
The second issue has been fixed.
– Trooper Z
Nov 19 '18 at 19:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380442%2fpython-monty-hall-n-number-of-doors%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's unclear what you're asking for. Your code runs and behaves fine to me.
– Daniel R. Livingston
Nov 19 '18 at 18:55
Posted the whole code now :)
– user10676306
Nov 19 '18 at 19:01
Can you post the error you're getting as well, and/or the expected behavior vs. the actual behavior? I.e., what exactly is going wrong, and where, and what should it be doing instead?
– Daniel R. Livingston
Nov 19 '18 at 19:04
Edited the error message in
– user10676306
Nov 19 '18 at 19:08
I fixed your second issue. Check my answer. If it fixed it, don't forget to click the checkmark.
– Trooper Z
Nov 19 '18 at 19:29