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

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

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

问题

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

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

You are missing a closing parenthesis. It should be:

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

Here's the corrected code:

  1. Sum=0
  2. x1=int(input('insert a number= '))
  3. x2=int(input('insert another number= '))
  4. Sum=x1+x2
  5. print('The Sum is:',Sum)
  6. while True:
  7. Javab=input('would you like to add another number? (y/n)')
  8. if Javab=='y':
  9. xn=int(input('insert another number :'))
  10. Sum=Sum+xn
  11. print('Sum is:', Sum)
  12. elif Javab=='n':
  13. break
  14. else:
  15. 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?

  1. Sum=0
  2. x1=int(input('insert a number= '))
  3. x2=int(input('insert another number= '))
  4. Sum=x1+x2
  5. print('The Sum is:',Sum)
  6. while True :
  7. Javab=input('would you adding another number? :(y/n)')
  8. if Javab=='y':
  9. xn=int(input('insert another number :')
  10. Sum=Sum+xn
  11. print('Sum is:', Sum)
  12. elif Javab=='n':
  13. break
  14. 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:

  1. Sum=0
  2. x1=int(input('insert a number= '))
  3. x2=int(input('insert another number= '))
  4. Sum=x1+x2
  5. print('The Sum is:',Sum)
  6. while True :
  7. Javab=input('would you adding another number? :(y/n)')
  8. if Javab=='y':
  9. xn=int(input('insert another number :'))
  10. Sum=Sum+xn
  11. print('Sum is:', Sum)
  12. elif Javab=='n':
  13. break
  14. 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:

  1. Sum=0
  2. x1=int(input('insert a number= '))
  3. x2=int(input('insert another number= '))
  4. Sum=x1+x2
  5. print('The Sum is:',Sum)
  6. while True :
  7. Javab=input('would you adding another number? :(y/n)')
  8. if Javab=='y':
  9. xn=int(input('insert another number :'))
  10. Sum=Sum+xn
  11. print('Sum is:', Sum)
  12. elif Javab=='n':
  13. break
  14. 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:

确定