为什么我的 Python 代码在我回答“否”时表现得像是在回答“是”?

Why does my Python code act like I'm answering yes to a question when I'm answering no?

为什么我的代码在回答“否”时表现得像是在回答“是”?

在我的这部分代码中:

  scrollTxt("Your are woken up at 07:30 by the guards going around banging on the cell doors. Your roommate " + orange + roommate + cyan + ", groans as they pull themselves out of their bed. They turn to you, and say " + purple + "\"How about we bust out, you know prison-escape movie style?\"" + green + "[Yes]" + cyan + " or " + green + "[No] " + cyan)
  ans = str(input()).lower()
  if ans == 'yes' or 'yea' or 'yeah' or 'sure' or 'ok' or 'k':
    print("  ")
    scrollTxt(cyan + "\"" + blue + "Urr... sure, let's do it!" + cyan + "\" you say.\n\n" + white + roommate + white + " will remeber that. They are happy.\n\n" + purple + "\"Ok, here's the plan. We are going to lay low for a day or two, get on the good side of all the guards. I'll formulate the rest of the plan tonight.\" " + orange + roommate + cyan + " says with a smile.")

    roommateFriend = True

    scrollTxt(cyan + "\n\nYou stand up, get dressed, and walk out with your roommate (and new friend) " + orange + roommate + cyan + ".")
    scrollTxt(cyan + "\n\nYou and " + orange + roommate + cyan + " walk to roll call. You get there 5 minutes before start, and before anyone else.\n\n" + purple + "\"Good job!\" " + cyan + "one of the gaurds says to you both.\n\nYou both smile and stand in your allocated locations next to each other.")

    scrollTxt(cyan + "\n\nAfter a few minutes the other prisoners start to turn up.\n\n" + purple + "\"Took you long enough!\" " + cyan + "the gaurd that congratulated you says," + purple + " \"Why can't you be more like these two?\"" + cyan + " He gestures to you and " + orange + roommate + cyan + ". You both smile again and exchange happy looks.")
    
  else:
    print(" ")
    scrollTxt(cyan + "\"" + blue + "Nah, I'll stay here, thanks." + cyan + "\"" + cyan + " you say.\n\n" + white + roommate + white + " will remeber that. They are upset and annoyed at you.\n" + purple + "\n\"Fine, suit yourself.\" " + orange + roommate + cyan + " says with a scowl.")
    roommateFriend = False
    
    scrollTxt(cyan + "\n\n\"" + ICyan + "15 minutes till Roll Call!" + cyan + "\"" + cyan + " the guards shout.\n\n"  + cyan + "\"" + blue + "We best go." + cyan + "\"" + cyan + " you say.\n\n" + purple + "\n\"Yeah, whatever.\" " + orange + roommate + cyan + " says, still mad at you.")```

无论你对“我们出狱怎么样,你知道越狱电影风格吗?”这个问题怎么说,即使你说不,它也会在“if ans == 'yes' 或 'yea' 或 'yeah' 或 'sure' 或 'ok' 或 'k':",所以“Urr... 当然,让我们开始吧!”,等等。 .

如果不是 'yes' 或 'yea' 或 'yeah' 或 'sure' 或 'ok' 或 [=32,它应该在 else 下打印内容=],然而,它没有。

完整代码如下:

from random import choice as chce
from random import randint as rand
import pyfiglet





cyan = "3[1;36m"
orange = "3[1;33m"
green = "3[1;32m"
blue = "3[0;34m"
purple = "3[0;95m"
white="3[0;37m"
ICyan="3[0;96m"

import sys
def scrollTxt(text):
  for char in text:
    sys.stdout.write(char)
    sys.stdout.flush()
    slp(0.03)

global roommateFriend
roommate = None
crimes = ["First-degree Murder", "Second-degree Murder", "Attemped Murder", "Arson", "Drug Abuse", "Domestic Abuse", "Burglary", "Theft", "Robbery", "Fraud", "Kidnapping", "Shoplifting", "Identity Theft", "Vandalism", "Bribery", "Computer Fraud", "Credit Card Fraud", "Debit Card Fraud", "Insurance Fraud", "Tax Evasion", "Tax Fraud", "Failure to obey a Police Order", "Causing death whilst dangerously driving"]
crime = chce(crimes)
age = rand(14, 25)
def roommatePicker(file_name):
  with open(file_name, 'r') as file:
    lines = file.readlines()
    global roommate
    roommate = chce(lines)
    roommate = roommate.strip('\n')

def intro():
  for x in range (0,4):  
    b = "Loading" + "." * x
    print (b, end="\r")
    slp(1)

  intro = cyan + "Hello. Today, you were arrested. Your aim is to escape prison, but there may be more than one way. Who do you trust? What do you trust?\n\nFirst of all, the guards want to know your name. (Remember, this does not have to be your name. You can make up a name or use a different name if you would like to.)" + green + "\nWhat is it? " + cyan

  scrollTxt(intro)
  name = str(input()).capitalize()

  if name in open("boyNames").read():
    gender = "Male"
    roommatePicker("boyNames")
  elif name in open("girlNames").read():
    gender = "Female"
    roommatePicker("girlNames")
  else:
    scrollTxt(cyan + "What is your gender? (Remember, this does not have to be the gender you identify as. You can use Male or Female, no matter what you are in real life.) " + green + "[Male]" + cyan + " or " + green +"[Female] ") #Inplement other genders (non-bianry, other, all, etc.).
    ans = str(input()).lower()
    if ans == 'male':
      f = open("boyNames", "a")
      f.write(name + "\n")
      f.close()
      roommatePicker("boyNames")
      gender = "Male"
    elif ans == 'female':
      f = open("girlNames", "a")
      f.write(name + "\n")
      f.close()
      roommatePicker("girlNames")
      gender = "Female"


  intro2 = cyan + "The guards come up to you, and say, \"Hello, " + orange + name + cyan + ", and welcome to Rhineland Prison. You have been arrested for " + orange + crime + cyan + ", but you knew that already. The " + orange + gender + cyan + " dorms are over there. Make sure to go to the " + orange + str(age) + cyan + " year old section. Roll call will be at 7:45.\"\n"

  scrollTxt(intro2)

def dayOne():
  scrollTxt("Your are woken up at 07:30 by the guards going around banging on the cell doors. Your roommate " + orange + roommate + cyan + ", groans as they pull themselves out of their bed. They turn to you, and say " + purple + "\"How about we bust out, you know prison-escape movie style?\"" + green + "[Yes]" + cyan + " or " + green + "[No] " + cyan)
  ans = str(input()).lower()
  if ans == 'yes' or 'yea' or 'yeah' or 'sure' or 'ok' or 'k':
    print("  ")
    scrollTxt(cyan + "\"" + blue + "Urr... sure, let's do it!" + cyan + "\" you say.\n\n" + white + roommate + white + " will remeber that. They are happy.\n\n" + purple + "\"Ok, here's the plan. We are going to lay low for a day or two, get on the good side of all the guards. I'll formulate the rest of the plan tonight.\" " + orange + roommate + cyan + " says with a smile.")

    roommateFriend = True

    scrollTxt(cyan + "\n\nYou stand up, get dressed, and walk out with your roommate (and new friend) " + orange + roommate + cyan + ".")
    scrollTxt(cyan + "\n\nYou and " + orange + roommate + cyan + " walk to roll call. You get there 5 minutes before start, and before anyone else.\n\n" + purple + "\"Good job!\" " + cyan + "one of the gaurds says to you both.\n\nYou both smile and stand in your allocated locations next to each other.")

    scrollTxt(cyan + "\n\nAfter a few minutes the other prisoners start to turn up.\n\n" + purple + "\"Took you long enough!\" " + cyan + "the gaurd that congratulated you says," + purple + " \"Why can't you be more like these two?\"" + cyan + " He gestures to you and " + orange + roommate + cyan + ". You both smile again and exchange happy looks.")
    
  else:
    print(" ")
    scrollTxt(cyan + "\"" + blue + "Nah, I'll stay here, thanks." + cyan + "\"" + cyan + " you say.\n\n" + white + roommate + white + " will remeber that. They are upset and annoyed at you.\n" + purple + "\n\"Fine, suit yourself.\" " + orange + roommate + cyan + " says with a scowl.")
    roommateFriend = False
    
    scrollTxt(cyan + "\n\n\"" + ICyan + "15 minutes till Roll Call!" + cyan + "\"" + cyan + " the guards shout.\n\n"  + cyan + "\"" + blue + "We best go." + cyan + "\"" + cyan + " you say.\n\n" + purple + "\n\"Yeah, whatever.\" " + orange + roommate + cyan + " says, still mad at you.")





intro()
slp(0.5)
print(pyfiglet.figlet_format("Day One"))
slp(0.5)
dayOne()

slp(2)

有人能帮忙吗?

谢谢:)

这一行是错误的:

if ans == 'yes' or 'yea' or 'yeah' or 'sure' or 'ok' or 'k':

or 'yea' 将始终返回为真。改为这样做。

if ans in ('yes', 'yea', 'yeah', 'sure', 'ok', 'k'):