鞋尺转换器功能

时间:2015-03-24 17:34:31

标签: python function

我正在尝试制作鞋码转换器功能。但是这个程序打印出奇怪的东西,如:

"You need function shoe_size at 0x030236F0> sized shoes"

我该怎么办?这是我的代码:

 def shoe_size(foot_size):
    shoe_size = (foot_size + 1,5) * 3 / 2
    return shoe_size

foot_size = (input("Enter your foot size: "))

print ("You need " + str(shoe_size) + " sized shoes")

4 个答案:

答案 0 :(得分:2)

这里有一些错误或至少是潜在的错误检查我对输入语句所做的更改,你通常不需要一个与它所在函数同名的变量:

def shoe_size(given_size):
    #foot_size = (foot_size + 1,5) * 3 / 2 #This multiples a tuple (, as .)
    return (given_size + 1.5) * 3 / 2 #returning float (1.5 makes float)

foot_size = int(input("Enter your foot size: ")) 
#figured you wanted a type cast here: used int just change to float if halfs wanted

print ("You need " + str(shoe_size(foot_size)) + " sized shoes") 
#this converts and prints the size: Your original was treating the function as a variable

答案 1 :(得分:1)

您需要在打印声明中为foot_size方法提供shoe_size变量:str(show_size(foot_size))

答案 2 :(得分:0)

def shoe_size(foot_size):
    shoe_size = (foot_size + 1.5) * 3 / 2
    return shoe_size

foot_size = (input("Enter your foot size: "))

print ("You need " + shoe_size(foot_size) + " sized shoes")

答案 3 :(得分:0)

这是更正的脚本:

def shoe_size(foot_size):
   shoe_size = (foot_size + 1.5) * 3 / 2
   return shoe_size

foot_size = (input("Enter your foot size: "))

print ("You need " + str(shoe_size(foot_size)) + " sized shoes")