我正在编写一个基本的计算器来测试我有限的编程知识/技能,使用python并遇到了第77行的语法错误,其中我不知道它有什么问题。任何有用的建议都会非常感激。
one_ = 0
two_ = 0
three_ = 0
one_operator = 0
second_operator = 0
third_operator = 0
question = 0
answer = 0
answer2 = 0
one_ = raw_input("Enter the first number: ")
if one_.isalpha() == True:
print('Invalid input, please start again.')
else:
print(one_number)
one_operator = raw_input("Enter the first operator: ")
if one_operator.isalpha() == True:
print('Invalid input, please start again.')
elif one_operator == "":
print('Invalid input, please start again.')
elif len(one_operator) > 1:
print('Invalid input, please start again.')
else:
print(one_ + " " + one_operator)
two_ = raw_input("Enter the second number: ")
if two_.isalpha() == True:
print('Invalid input, please start again.')
else:
print(one_ + " " + one_operator + " " + two_)
if one_operator.find('*') != -1:
answer = float(one_) * float(two_)
print(one_ + " " + one_operator + " " + two_ + " = " + str(answer))
elif one_operator.find('/') != -1:
answer = float(one_) / float(two_)
print(one_ + " " + one_operator + " " + two_ + " = " + str(answer))
elif one_operator.find('+') != -1:
answer = float(one_) + float(two_)
print(one_ + " " + one_operator + " " + two_ + " = " + str(answer))
elif one_operator.find('-') != -1:
answer = float(one_) - float(two_)
print(one_ + " " + one_operator + " " + two_ + " = " + str(answer))
else:
print('Invalid input, please start again.')
question = raw_input('Do you wish to modify the answer? y/n')
if question == 'yes' or 'y':
third_operator = raw_input('Enter the third operator: ')
if one_operator.isalpha() == True:
print('Invalid input, please start again.')
elif one_operator == "":
print('Invalid input, please start again.')
elif len(one_operator) > 1:
print('Invalid input, please start again.')
elif len(one_operator) == 1:
print(str(answer) + third_operator)
three_ = raw_input('Enter the third number: ')
if three_.isalpha() == True:
print('Invalid input, please start again.')
elif three_.isalpha() == False:
if third_operator.find('*') != -1:
answer2 = float(answer) * float(three_)
print(str(answer) + ' * ' + str(three_) + ' = ' + str(answer2))
elif third_operator.find('/') != -1:
answer2 = float(answer) / float(three_)
print(str(answer) + ' / ' + str(three_) + ' = ' + str(answer2))
elif third_operator.find('+') != -1:
answer2 = float(answer) + float(three_)
print(str(answer) + ' + ' + str(three_) + ' = ' + str(answer2))
elif third_operator.find('-') != -1:
answer2 = float(answer) - float(three_)
print(str(answer) + ' - ' + str(three_) + ' = ' + str(answer2))
else:
print('Invalid input, please start again')
else:
print('Invalid input, please start again.')
else:
print('Invalid input, please start again.')
print(str(answer)
elif str(question) == 'n':
print('Finished')
else:
print('Finished')
# question = raw_input("Do you wish to compute 2 or 3 numbers?")
答案 0 :(得分:2)
上面的一行(第76行)缺少右括号:
...
print(str(answer) # <-- here
elif str(question) == 'n':
print('Finished')
...