0
from random import randint

isRunning =True

while isRunning:
    dice1 = randint(1,7)
    dice2 = randint(1,7)
    print("The first die landed on ℅d and the second landed on ℅d." ℅ (dice1,dice2))
   user_input = input("Contiue? Yes or No?\n>")

   if user_input == "Yes" or "yes":
        print("="*16)

   elif user_input == "No" or "no":
        isRunning = False

I feel like I'm making such a simple mistake and when I decided to look into global variables and what not it still doesn't help. Could anyone explain why the while loop doesn't terminate, although the variable was set to false.

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
Don
  • 11
  • 3
  • 1
    Check your indenting. It looks from what you've posted as though everything from "user_input = " down is indented differently to the 3 lines above it. Python requires indenting to be 100% identical on each line. (Although this may be just a transposition issue when posting) – Son of a Beach Nov 21 '16 at 04:29
  • Possible duplicate of [How do I test one variable against multiple values?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – TigerhawkT3 Nov 21 '16 at 05:55

1 Answers1

0

if user_input== "Yes" or "yes" should be

if user_input== "Yes" or user_input =="yes", alternatively it's equivalent to if any(user_input==keyword for keyword in["Yes", "yes"]):

your original if clause is splitting to if user_input=="Yes" or if "yes" and if "yes" always true, therefore your if-elseif clause always go to if clause.

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125