raw_input循环错误需要两个答案



在这一段代码中,当回答任何一个问题时,它会第二次询问它,然后才会返回结果。说如果它问你你拿起棍子吗?(输入 Y 或 N)并且您回答 Y,它将再次提示问题。我正在寻找解决此问题的方法,知道吗?所讨论的功能是选择1

    # Project
# Created By: Misha 
import time
import random
weapon = 0
def intro():
    time.sleep(3)
    print "You wake up."
    time.sleep(1)
    print "..."
    time.sleep(1)
    print "You are surrounded by white tiled walls and floors"
    time.sleep(2)
    print "You do not remember anything"
    time.sleep(1)
    print "Ahead of you are two doors."
    time.sleep(2)
    print "One leads to the left and the other to the right"
    print ""
def choose_door1():
  chosen_door1 = ""
  while chosen_door1 != "L" and chosen_door1 != "R":
    time.sleep(2)
    chosen_door1 = raw_input("Which door do you take? (input L or R)")
  return chosen_door1
def proceed_1(chosen_door1):
  if chosen_door1 == "L":
    time.sleep(2)
    print "You head through the left door"
    time.sleep(2)
    print "There is a stick lying on the ground"
    time.sleep(2)
  elif chosen_door1 == "R":
    time.sleep(2)
    print "You head through the right door"
    time.sleep(2)
    print "There is a keypad on the wall"
def choice1(chosen_door1):
  if chosen_door1 == "L":
    choice_left1 = ""
    while choice_left1 != 'Y' and choice_left1 != 'N':
      time.sleep(2)
      print ""
      choice_left1 = raw_input("Do you pick up the stick? (input Y or N)")
    return choice_left1
  elif chosen_door1 == "R":
    choice_right1 = ""
    while choice_right1 != 'Y' and choice_right1 != 'N':
      time.sleep(2)
      print ""
      choice_right1 = raw_input("Do you input anything in the keypad? (input Y or N)")
    return choice_right1
def action_left1(choice_left1):
  if choice_left1 == "Y":
    print "You equipped the Stick!"
    weapon = 1
  elif choice_left1 == "N":
    print "You left the stick lying on the ground"
  else:
    print "ERROR"
def action_right1(choice_right1):
  if choice_right1 == "Y":
    print "You decided to input something into the keypad"
    print ""
  elif choice_right1 == "N":
    print "You decided to not enter anything into the keypad"
    time.sleep(1)
    print "You went back the way you came and went into the left door"

intro()
chosen_door1 = choose_door1()
proceed_1(chosen_door1)
choice1(chosen_door1)
if chosen_door1 == "L":
  action_left1(choice1(chosen_door1))
elif chosen_door1 == "R":
  action_right1(choice1(chosen_door1))

删除

 if chosen_door1 == "L":
    action_left1(choice1(chosen_door1))
 elif chosen_door1 == "R":
    action_right1(choice1(chosen_door1))

只需删除第 82 行 choice1(chosen_door1)

intro()
chosen_door1 = choose_door1()
proceed_1(chosen_door1)
choice1(chosen_door1) # REMOVE THIS LINE
if chosen_door1 == "L":
  action_left1(choice1(chosen_door1))
elif chosen_door1 == "R":
  action_right1(choice1(chosen_door1))

最新更新