Python期望在raw_input中缩进

时间:2016-02-26 22:15:32

标签: python python-2.7

我无法找到专门针对我的问题的任何内容。 Python期望在raw_input内部使用缩进块。

relations = 0
firstNumber = 0
secondNumber = 0
def additionProblem(x, y):
    answer = x + y
    return answer
def askingTheNumbers(self):
    firstNumber = int(raw_input("What is the first number?"))
    secondNumber = int(raw_input("What is the second number?"))
import datetime
now = datetime.datetime.now
while True:
    firstResponse = raw_input("Hi! I am a really bad AI created by none other than (names removed for privacy. How was your day?")
while True:
    if firstResponse.lower() in ['good', 'great', 'amazing'] and relations == 0:
    artificialResponse = raw_input("Wow! That's great! I can do very limited things right now. All I'm programmed to do is math and the time.")
        relations = 1
    if relations == 1:
        artificialResponse = raw_input("Would you like me to do anything else?")
    if artificialResponse.lower() in [time]:
        whatTimeIsIt = raw_input("Would you like to know the year, month, day, hour, minute, second, or microsecond? You can choose multiple if you want.")
        if whatTimeIsIt.lower() in ['year']:
            print "Current year: %d" % now.year
        if whatTimeIsIt.lower() in ['month']:
            print "Current month: %d" % now.month
        if whatTimeIsIt.lower() in ['day']:
            print "Current day: %d" % now.day
        if whatTimeIsIt.lower() in ['hour']:
            print "Current hour: %d" % now.hour
        if whatTimeIsIt.lower() in ['minute']:
            print "Current minute: %d" % now.minute
        if whatTimeIsIt.lower() in ['second']:
            print "Current minute: %d" % now.second
        if whatTimeIsIt.lower() in ['microsecond']:
            print "Current microsecond (though I don't know why you care): %d" % now.microsecond
    elif artificialResponse.lower() in ['math']:
        mathProblem = raw_input("Great! Would you like me to do addition, multiplication, division, or multiplication?")
        if mathProblem.lower() in ['addition']:
            askingTheNumbers(pass)
            additionAnswer = additionProblem(firstNumber, secondNumber)
            print "The answer is", additionAnswer

在第16行,它希望程序有一个缩进块,但我完全不知道为什么会这样。这也是我在python中的第一个真正的项目,所以告诉我你是否看到任何可以改进的东西。

1 个答案:

答案 0 :(得分:0)

我运行了你的代码并在第10行而不是第16行收到错误。第10行需要缩进。我修复了这个问题,运行了代码,并在第33行收到错误。您不能将pass保留字用作函数的参数。不带参数的函数调用只是一个空参数列表()。我修复了这个错误后运行你的程序,它开始执行消息:

Hi! I am a really bad AI created by none other than (names removed for privacy. How was your day?

假设这是您所期望的,那么语法错误应该都很好。但可能不是语义问题。我假设您不打算使用一行无限循环,但后面的其余代码将成为该循环的一部分。

正如他们所说,其余部分留给学生练习。