使用浮点数调用函数



嗨,我正在尝试解决这个问题。我不断收到一条错误消息,说

不能将序列乘以类型为"float"的非 int

我也在使用 tkinter 模块。

list=[]
print amount.get()     #Using the Tkinter Spinbox widget, .get()
                       #retrieves the amount/input in that widget
if amount.get() > 0:
    list.append(amount.get())
    amount = 0
    for a in list:             #Makes the number in a list a float no. 
        for b in a.split():
            try:
                amount += float(b)
            except:
                pass
    print amount
    function_one() * amount  #I'm trying to call the function 
                             #definition with the amount but I get the 
                             #error message         
    del list[0] #delete the amount for the user to input a different 
                #number

我正在尝试使用"数量"的次数(来自"if-statement"的数字"金额"(调用该函数:

def function_one():
   print "Select"

上面的定义中有更多的变量等。您不必创建 tkinter 小部件等,但修复如何使用次数调用函数的解决方案会很棒!

如果您仍然感到困惑,我很抱歉,例如,如果我的金额 = 5,我希望该函数被调用 5 次。

请,谢谢你:)

你能不能使用 for 循环,即:

for i in range(int(amount.get())): 
    function_one()

最新更新