# Does anyone know why this code isnt working as intended?

**URL:** <https://discuss.python.org/t/does-anyone-know-why-this-code-isnt-working-as-intended/39417>\
**Category:** Python Help\
**Tags:** help\
**Created:** [November 23, 2023, 12:56pm UTC](https://discuss.python.org/t/does-anyone-know-why-this-code-isnt-working-as-intended/39417 "2023-11-23T12:56:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![YTDUDE](https://avatars.discourse-cdn.com/v4/letter/y/c37758/32.png) [@YTDUDE](https://discuss.python.org/u/YTDUDE)\
**Post date:** [November 23, 2023, 12:56pm UTC](https://discuss.python.org/t/does-anyone-know-why-this-code-isnt-working-as-intended/39417/1 "2023-11-23T12:56:21Z")

</div>

```auto
import random

options = ["goat", "goat", "car"]

def monty_hall_stick(number_of_goes):
    games_played = 0
    wins = 0
    while games_played < number_of_goes:
        random.shuffle(options)
        guess = random.choice(options)
        if guess == "car":
            wins = wins + 1
        games_played = games_played + 1
    decimal = wins / number_of_goes
    percentage = decimal * 100
    percentage = percentage // 1
    print("The win percentage of sticking with your first choice is", percentage, "%")
    

def monty_hall_switch(number_of_goes):
    games_played = 0
    wins = 0
    while games_played < number_of_goes:
        options = ["goat", "goat", "car"]
        random.shuffle(options)
        guess = random.choice(options)
        guess = options.index(guess)
        del options[guess]
        options.remove("goat")
        guess = random.choice(options)
        if guess == "car":
            wins = wins + 1
        games_played = games_played + 1
    decimal = wins / number_of_goes
    percentage = decimal * 100
    percentage = percentage // 1
    print("The win percentage of swapping after revealed goat is", percentage, "%")
    
print("Welcome to the Monty Hall problem simulator")
method = input("Would you like to use the Switch method (Sw) or the Stick method (St)?: ")
method = method.lower
number_of_goes = int(input("How many games should the simulator run?: "))

if method == "sw" or "switch":
    monty_hall_switch(number_of_goes)
elif method == "st" or "stick":
    monty_hall_stick(number_of_goes)
else:
    print("Thats not a valid method. Try again")

```

---

<div class="post-metadata">

**Author:** ![abessman](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abessman/32/8367_2.png) [@abessman](https://discuss.python.org/u/abessman)\
**Post date:** [November 23, 2023, 1:36pm UTC](https://discuss.python.org/t/does-anyone-know-why-this-code-isnt-working-as-intended/39417/2 "2023-11-23T13:36:31Z")

</div>

Because of this line:

> [@YTDUDE](#):
>
> `if method == "sw" or "switch":`

See:

> <https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true-how-can-i-compare-a-to-al>

---

<div class="post-metadata">

**Author:** ![rob42](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rob42/32/8218_2.png) [@rob42](https://discuss.python.org/u/rob42)\
**Post date:** [November 23, 2023, 3:59pm UTC](https://discuss.python.org/t/does-anyone-know-why-this-code-isnt-working-as-intended/39417/3 "2023-11-23T15:59:58Z")

</div>

Another thing to be aware of:

This…  
`method = method.lower`  
sound be…  
`method = method.lower()`

Better still…  
`method = input("Would you like to use the Switch method (Sw) or the Stick method (St)?: ").lower()`

Also (not that it makes too much of a difference here) when you have code such as `if method == "sw" or "switch":` personally, I’d use `if method in ("sw", "switch")`  
That way it’s an easy code edit to add more options to the tuple should more options be needed.
