Python 我不明白这个代码有什么问题

Python 我不明白这个代码有什么问题,python,python-2.5,Python,Python 2.5,我在下面的代码中遇到了一个错误,我不明白它到底出了什么问题 我只是想学习如何做到这一点,这是一个测试 我不知道什么地方出了问题,也不知道如何解决 print "Would you like to see today's weather?" answer = input if answer = "yes": print "Follow Link: http://www.weather.com/weather/right-now/Yorktown+VA+23693 " elif answ

我在下面的代码中遇到了一个错误,我不明白它到底出了什么问题

我只是想学习如何做到这一点,这是一个测试

我不知道什么地方出了问题,也不知道如何解决

print "Would you like to see today's weather?"

answer = input

if answer = "yes":
    print "Follow Link: http://www.weather.com/weather/right-now/Yorktown+VA+23693 "
elif answer = "no":
    print "Very well, would you like to play a guessing game?"
    if answer = "yes":
        import random

        secret = random.randint (1, 99)
        guess= 0
        tries= 0

        print "AHOY!  I'm the Dread Pirate Roberts, and I have a secret!"
        print "It is a number from 1 to 99. I'll give you 6 tries. "

        while guess != secret and tries < 6:
            guess = input("What's your guess? ")
            if guess < secret:
                print "Too low, ye scurvy dog!"
            elif guess > secret:
                print "Too high, landlubber!"
            tries = tries + 1
            if guess == secret:
                print "Avast! Ye got it! Found my secret ye did!"
    elif answer = "no":
        print "Thank you, and goodnight."
第一个错误是:

if answer = "yes": #This would be giving you a syntax error
您要做的是对代码中的每个测试用例进行相同的比较:

if answer == "yes": #Notice the double equals to sign
此外,您还需要调用输入函数:

answer = input() #Notice the parentheses 
第三个错误这是一个逻辑错误:

print "Very well, would you like to play a guessing game?"
#You are missing an input statemtent
if answer = "yes":
同样的错误:

print "It is a number from 1 to 99. I'll give you 6 tries. "
#You are agin missing an input statement
while guess != secret and tries < 6:

除了AshRj指出的以外,还有两个更明显的错误:

answer = input
这会将实际的函数输入分配给应答,而不是调用函数。此外,您可能希望改用原始输入。因此,使用answer=raw\u输入


您并没有在这些比较之间获取新的答案,所以当您再次测试时,答案仍然是否定的。

您会得到什么错误?你从哪里弄来的?到底是什么问题?请在原始帖子中添加问题的描述。确切地说,用户1938922什么是错误无效语法导致您在ifI中使用赋值运算符?我认为您需要答案=input@Dolda2000做出了改变。谢谢
elif answer = "no":
    print "Very well, would you like to play a guessing game?"
    if answer = "yes":