首页 > 解决方案 > + 不支持的操作数类型:“function”和“int”错误

问题描述

我的代码:

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 计数函数中。我是 python 新手,不知道为什么以及发生了什么。谢谢你的帮助 :)

标签: pythonfunctionfor-loop

解决方案


您在其中使用的所有东西range都是函数,而不是变量;您必须调用(添加调用括号)它们以获取它们的值,更改:

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

到(使用PEP8间距):

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

推荐阅读