我明白這些問題,但我不確定的事情是它說「使用函數」的部分。 這裏是我的代碼,並懷疑它是否可以接受;編寫一個程序,使用函數找出兩個數字的總和並計算它們的平均值?
x= int(input("Enter first number:"))
y= int(input("Enter second number:"))
sum=x+y
average=sum/2
print("Sum of the given two numbers is:", sum)
print("Average of the given numbers is:", average)
你可能希望創建功能平均水平。 'def sum(x,y):x + y;''和'def average(x,y):sum(x,y)/ 2;'順便說一句,StackOverflow並不是真正意圖爲你解決你的學業問題,而是一種資源來幫助你發現問題的解決方案。另外,如果您使用python 3.4,則可以使用statistics.mean並將這些數字放入數組中。 – Tr1gZer0
'int'是一個函數。 「輸入」和「打印」也是如此。儘管如此,你應該避免使用像sum這樣的內建函數名稱。 – miradulo