2014-03-03 43 views
-2

我編寫了一個基本的計算器來測試我有限的編程知識/技巧,使用python,並且在第77行中遇到了一個語法錯誤,我不知道它有什麼問題。任何有用的建議都會非常感激。-Python-我的代碼有什麼問題?語法錯誤

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

哪條線是線77?我不能(好吧,不想)數到那麼高...... – twalberg

回答

2

您有失蹤就行右括號以上(線76):

... 
     print(str(answer) # <-- here 
elif str(question) == 'n': 
    print('Finished') 
... 
+0

非常感謝你,我正在殺死哈哈 – user3376597