Python Forum
trouble with unexpected tokens
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trouble with unexpected tokens
#1
Question 
HI. I'am new to python but i was trying to do simple calcluator.
def number1():
   print("input first number")
   input() 
def number2():
   print("input second number")
   input()
def operation():
    print("+, or -, or *, or /") 
    input()
def score():
    if operation == ("-"):
        subst = float(number1) - float(number2)
        [error]print("score is{}" .format(subst)[/error]
    elif operation == ("+"):
        suma = float(number1) + float(number2)
        [error]print("score is{}" .format(suma)[/error]
    elif operation == ("/"):
        div = number1 / number2
        [error]print("score is{}" .format(div)[/error]
    elif operation == ("*"):
        mult = number1 * number2  
        print("score is{}" .format(mult)
    [error]else print("wrong input") [/error]                    
def last():
    number1()
    number2()
    operation()
    score()
last()
I don't know how to fix these errors. In the first three errors are unexpected token '<newline>' and last error is unexpected token 'else"
Reply
#2
Quote:I don't know how to fix these errors
Please show full error traceback (enclosed within bbcode error tags). Please post complete, unaltered error messages.
Reply
#3
Indeed, Larz is right: error messages are meant to tell you exactly what is wrong and on what line.

But I can give you already one hint:
print("score is{}" .format(subst)
Just count how many parenthesis you are opening and how many you are closing.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Delay in fetching kerberos tokens : python gssapi securitycontext unni10286 1 2,601 Apr-30-2018, 04:12 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020