Question

I am coding a basic calculator to test my limited knowledge/skill of programming, using python and have come accross an syntax error on line 77 of which I have no idea what is wrong with it. Any helpful suggestions would be geatly appreciated.

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?")
Was it helpful?

Solution

You have a missing closing parenthesis on the line above (line 76):

...
        print(str(answer)  # <-- here
elif str(question) == 'n':
    print('Finished')
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top