我必须创建一个输入,将其平方,然后返回数字的倒数。救命!!提示用户输入输入值在一行上打印倒数值在第二行上打印值的平方用描述符标签值
到目前为止,我已经
def main ():
print("this program sqaures your original number and gives back the reciprocal number")
print ()
x=eval(input("Please enter a number"))
发布于 2017-04-12 12:48:00
使用eval()
或exec()
用户输入并不是一个好主意。检查输入是否实际上是某种类型的数字也是一个好主意。您希望通过将输入与自身相乘来平方输入,然后在平方后的数字上返回1。如果你这样做是为了做家庭作业:你真丢脸。
def main ():
print("this program sqaures your original number and gives back the reciprocal number")
print ()
x = input("Please enter a number")
assert isinstance(x, int) or isinstance(x, float) # make sure its a number
xx = x*x # square the user input
return 1/xx
https://stackoverflow.com/questions/43360393
复制相似问题