我在初学者编程课程中,并且我应该让这段代码正常工作,我已经按照书中一遍又一遍的说法输入了它,我得到了一个无效的语法错误,在Python Idle中是def sum的高亮def(num1,num2) 我已经在书中找到了所有在线,并且还没有找到答案,说明为什么它会给我一个错误。
#this program uses the return value of a function
def main():
#Get the user's age
first_age = int(input('Enter your age: '))
#Get the user's best friend's age.
second_age = int(input("Enter your best friend's age: "))
#Get the sum of both ages
total = sum(first_age, second_age)
#Display the total age
print('Together you are', total, 'years old.')
#the sum function accepts two numeric arguments and
# return the sum of those arguments.
def sum(num1, num2):
result = num1 + num2
return result
#Call the main function
main()
SyntaxError: invalid syntax
答案 0 :(得分:0)
你编码运行。你有如下的确切缩进吗?我必须解决一些问题才能使其发挥作用。
The following number of users are logged in: