Python-raw_input无效

时间:2013-04-14 19:58:26

标签: python defined

好的,所以我把它改成了:

if input('a'):
      print ("You: Gimme a gun!")

if input('b'):
       print ("You: Fine")

但现在我没有选择它迫使我选择a然后在那之后它迫使我选择b,一旦我越过这个障碍我将剩下的比赛放在包里但是我真的需要帮助弄清楚这一点 附:我是愚蠢的小鸟

import time
Gimme=True
Fine=True




print ("James: Ah, it looks like subject 091-266 is awake")
time.sleep(4)
print ("Scarlet: Hello, do you remember anything? The crash or anything?")
time.sleep(4)
print ("You: What.... Where am I?")
time.sleep(3)
print ("Scarlet: Oh, where are my manners, this is the head quarters of the XionRepublic, Xion")                        
time.sleep(5)
print ("James: You were involved in Z-9102, code named Attack-Z")
time.sleep(4)
print ("Scarlet: We were able to pull you and three others out before we  were forced to...")                                             
print ("James: Exterminate Alpha Base 12.")
time.sleep(6)
print ("You: Exterminate?! Couldn't you just quarantine it?")
time.sleep(4)
print ("Scarlet: No, Alpha Base 12 had over 3,000 people in it, it was to risky to quarantine")      
time.sleep(5)
print ("James: Do you recognize these names, Noah, Alex or Robert?")
time.sleep(4)
print ("You: Yes Alex!? Why? Is he ok?!")
time.sleep(3)
print ("James: Yes, Yes he was one of the three.")
time.sleep(4)
print ("*ALARM! SECURITY BREACHED, SECURITY BREACHED*")
time.sleep(4)
print ("James: Scarlet lock the door!")
time.sleep(3)
print ("You: Whats going on?!")
time.sleep(3)
print ("James: Z's there here.")
time.sleep(3)
print ("*Screaming*")
time.sleep(2)
print ("You: I can fight!")
time.sleep(3)
print ("Scarlet: Trust me you are not in any condition to fight due to some of the drugs in you")   
print ("CHOICE")
print ("A.Gimme the gun!")
print ("B.Fine")

if raw_input() == Gimme:
    print ("You: Gimme a gun!")
if raw_input() == Fine:
    print ("You: Fine")

3 个答案:

答案 0 :(得分:3)

如果您使用的是新版本的python - 3.x.x - 则raw_input不再存在。请改用输入(提示)。它的工作原理基本相同。基本语法:

foo = input("some prompt"). 

它从标准输入文件或<stdin>读取一行是什么输入。它在()内打印提示,然后等待用户输入。示例:(>>>是命令行提示符,输出<<<

Command Line, interactive mode (or IDLE): 
>>> foo = input("GIMME SOME INPUT: ")  #tell it to take some input
<<<GIMME SOME INPUT: foo          # it prints out, "GIMME SOME INPUT:" user types in foo
>>> print(foo)
<<< foo

对您的修改的回复:

使用此:

print ("CHOICE")
print ("A.Gimme the gun!")
print ("B.Fine")
choice = input("What do you choose?")
if choice == 'A' or choice == 'a':
    #Some Action 
if choice == 'B' or choice == 'b': 
    #Some Other Action  

答案 1 :(得分:1)

您似乎正在使用Python 3.在Python 3中,raw_input() has been renamed to input()

答案 2 :(得分:1)

重新提出新问题:

  

但是现在我没有选择它迫使我选择a然后在那之后迫使我选择b

那是因为您正在调用input()两次,每次调用时,系统会提示您输入内容。您想将其称为一次,将您获得的值存储在变量中,并将该变量与可能的选择进行比较。