[英]Write a function which squares a number and then use it to write a function which takes three integers and returns the sum of their squares
Im new to python and cant figure out how to get these functions to call themselves.我是 python 新手,无法弄清楚如何让这些函数调用自己。 It asks for an input but no matter what gives 0 as the output.
它要求输入,但无论如何都给出 0 作为输出。 Can someone help debug?
有人可以帮忙调试吗?
userinput = input("Enter three numbers: ")
userinput = userinput.split(',')
finalsum = 0
finaldata = []
def formatinput(x):
sqrdata = []
for element in x:
sqrdata.append(int(element))
return(sqrdata)
def findsquare(x):
return (x*x)
def sumthesquares(y):
for element in y:
temp = findsquare(element)
finaldata.append(int(temp))
finalsum = finalsum + temp
return finalsum
def findthesquares(userinput):
finalsum = sumthesquares(formatinput(userinput))
print(finalsum)
Have you actually tried running your code?你真的试过运行你的代码吗? From what you've posted, it looks like you never actually call your functions...
从您发布的内容来看,您似乎从未真正调用过您的函数...
They're defined, but you're missing the actual calls, like formatinput(userinput)
.它们已定义,但您错过了实际调用,例如
formatinput(userinput)
。
For future reference, if you put something like print("Got here!")
into your functions, you can test that they're being called.为了将来参考,如果您将
print("Got here!")
放入您的函数中,您可以测试它们是否被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.