0
import turtle
import time
import colorama
from colorama import Style, Fore, Back
colorama.init()

def gametime():
  print("The game will start now.")



def firstanswer():
  print(Back.WHITE)
  print(Fore.CYAN)
  print("get a cup of chai as we wait")


def firstdenial():
  print("you dont get to play my game than humph")
  print("nah just playing")
  print("the long list of rules are... TL means top left, TM means top middle of the screen, TR means top right, ML means middle left of the screen, MM means the absulote MIDDLE of the screen, MR means middle right of the screen,BL means bottom left of the screen, BM means bottom middle of the screen, BR means bottom right of the screen ")
  ans3 = input("Do you understand now? ")
  if ans3 == "yes" or "Yes" or "Yeah" or "yeah" or "indubitably":
    gametime()
  else: 
    print ("well funk you, stupid delinquent instead of playing a game go read a book.")
    exit()

def gamedrive():


  print(colorama.Fore.GREEN, "tic-tac-toe")
  print(colorama.Style.DIM + colorama.Fore.BLUE , "the commands of this game are:")
  print("TL means top left TM means top mid TR means top right the bottom rows follow the same thinking ML is mid left BL is bottom left")
  print(Fore.RESET)
  ans1 = input("are the instructions clear? ")
  print(Style.RESET_ALL)
  if ans1 == "yes" or "Yes" or "Yeah" or "yeah" or "indubitably":
    firstanswer()
  else:
    firstdenial()



gamedrive()

question:

if ans1 == "yes" or "Yes" or "Yeah" or "yeah" or "indubitably":
    firstanswer()
  else:
    firstdenial()

So when running my code and inputting anything else the code still prints what's in the first line after

if ans1 == "yes" or "Yes" or "Yeah" or "yeah" or "indubitably":

my else code isn't working can anyone help me figure out how to fix my code so when you input anything other than yes, Yes, Yeah, yeah, or indubitably it will explain the full set of rules. but if you do type yes, Yes, Yeah, yeah, or indubitably to have the code run

def firstanswer():
  print(Back.WHITE)
  print(Fore.CYAN)
  print("get a cup of chai as we wait")

for some reason it does not print my else code could I possible get some explanation?

rv.kvetch
  • 9,940
  • 3
  • 24
  • 53
hatboi
  • 17
  • 2
  • Your statement is parsed as `if (ans1 == "yes") or ("Yes") or ("Yeah")...:`, and the string "Yes" is always True. – Tim Roberts Nov 13 '21 at 03:52

1 Answers1

1

For evaluating if multiple strings are contained in another string you can use in.

Kindly try replacing:

if ans1 == "yes" or "Yes" or "Yeah" or "yeah" or "indubitably":

with:

if ans1 in ['yes','Yes','Yeah','yeah','indubitably']:

For example:

ans1 = "Yes"
if ans1 in ['Yes','yeah','Yeah']:
  print("Ok")
else:
  print("Not Ok")

Evaluates to True and prints Ok

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
  • 2
    Not the downvoter but it might be because you didn't explain that each term is being evaluated individually – 0x263A Nov 13 '21 at 02:33