簡體   English   中英

+不支持的操作數類型:“函數”和“整數”錯誤

[英]Unsupported operand type(s) for +: 'function' and 'int' error

我的代碼:

def start_input():
    start = int(input("\nAt what number shall we start, master? "))
    return start

def finish_input():
    end = int(input("\nwhen shall i finish, master? "))
    return end

def step_input():
    rise = int(input("\nby what ammount shall your numbers rise, master? "))
    return rise

def universal_step():
    rise = 3
    return rise

def the_counting():
    print("your desired count: ")
    for i in range ( start_input, finish_input +1, step_input): #can be also changed for automated step
        return print(i, finish_input ="  ")

def main():
    start_input()
    finish_input()
    step_input() #This can be changed for the universal_step function for no input if wanted
    the_counting()

main()

input("\n\nPress the enter key to exit.")

因此,無需將代碼放入以前可以完全發揮作用的函數中,現在我得到的只是def計數函數中的“ +不支持的操作數類型:'function'和'int'error”。 我是python的新手,不知道為什么和發生了什么。 謝謝你的幫助 :)

您在range使用的所有東西都是函數,而不是變量。 您必須調用(添加調用括號)以獲取其值,並進行以下更改:

for i in range ( start_input, finish_input +1, universal_step):

至(具有PEP8間距):

for i in range(start_input(), finish_input() + 1, universal_step()):

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM