-3
我找不到任何專門針對我的問題的東西。 Python期望在raw_input內真正地使用縮進塊。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項目,所以告訴我,如果你看到任何可以改進的東西。
它不希望在該函數中使用縮進*。整行需要縮進。在行的開頭放四個空格,並觀察發生了什麼。魔法! – zondo
這是XD無法相信的問題,我之前沒有注意到。謝謝! – Thepicheese
所有你需要做的就是像Python告訴你的縮進行16。在Python中讀取Traceback錯誤是調試Python的好方法。 – MarkyPython