请告诉我如何在这段代码中去除语法错误。

huangapple go评论118阅读模式
英文:

Please let me know how can I remove the syntaxerror in this code

问题

You have a syntax error in the code at this line:

xn=int(input('insert another number :'))

You are missing a closing parenthesis. It should be:

xn=int(input('insert another number :'))

Here's the corrected code:

Sum=0
x1=int(input('insert a number= '))
x2=int(input('insert another number= '))
Sum=x1+x2
print('The Sum is:',Sum)
while True:
    Javab=input('would you like to add another number? (y/n)')
    if Javab=='y':
        xn=int(input('insert another number :'))
        Sum=Sum+xn
        print('Sum is:', Sum)
    elif Javab=='n':
        break
else:
    print('Sum is:', Sum)

It should now work correctly for calculating the summation of a sequence of numbers.

英文:

why I have syntax error for Sum=Sum+xn?

Sum=0
x1=int(input('insert a number= '))
x2=int(input('insert another number= '))
Sum=x1+x2
print('The Sum is:',Sum)
while True :
        Javab=input('would you adding another number? :(y/n)')
        if Javab=='y':
            xn=int(input('insert another number :')
            Sum=Sum+xn
            print('Sum is:', Sum)
        elif Javab=='n':
        break
else : print('Sum is:', Sum)

I need to calculate the summation of a sequences of numbers.

答案1

得分: 2

You are missing a parentheses in the line xn=int(input('insert another number :'.

Change it to xn=int(input('insert another number :')) as shown:

Sum=0
x1=int(input('insert a number= '))
x2=int(input('insert another number= '))
Sum=x1+x2
print('The Sum is:',Sum)
while True :
    Javab=input('would you adding another number? :(y/n)')
    if Javab=='y':
        xn=int(input('insert another number :'))
        Sum=Sum+xn
        print('Sum is:', Sum)
    elif Javab=='n':
        break
else : print('Sum is:', Sum)
英文:

You are missing a parentheses in the line xn=int(input('insert another number :').

Change it to xn=int(input('insert another number :')) as shown:

Sum=0
x1=int(input('insert a number= '))
x2=int(input('insert another number= '))
Sum=x1+x2
print('The Sum is:',Sum)
while True :
    Javab=input('would you adding another number? :(y/n)')
    if Javab=='y':
        xn=int(input('insert another number :'))
        Sum=Sum+xn
        print('Sum is:', Sum)
    elif Javab=='n':
        break
else : print('Sum is:', Sum)

Note that syntax errors are almost always caused by the line above the line raising the error.

huangapple
  • 本文由 发表于 2023年5月14日 06:34:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245127.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定