英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论