python - + 不支持的操作数类型:“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 新手,不知道为什么以及发生了什么。谢谢你的帮助 :)
解决方案
您在其中使用的所有东西range
都是函数,而不是变量;您必须调用(添加调用括号)它们以获取它们的值,更改:
for i in range ( start_input, finish_input +1, universal_step):
到(使用PEP8间距):
for i in range(start_input(), finish_input() + 1, universal_step()):
推荐阅读
- javascript - 使用 jQuery 隐藏/显示元素
- java - 如何在 Spring Boot 中公开诸如可下载链接之类的资源
- uwp - ReactiveUI - 如何共享属性?
- ios - 如何确定是否启用了 ASAM?
- javascript - 给定特定输入时如何重定向到特定页面
- scala - 找不到参数解析器的隐式值:play.api.mvc.BodyParser[Any]
- bash - JMeter Beanshell 断言:如何保存 Runtime.getRuntime().exec("ifconfig | grep \"${IpAddress}\" | wc -l") 的值?
- java - 检测服务器套接字关闭
- python - 用唯一列表中的后续值替换列值
- ios - 如何禁用 ScrollView 项目上的多个按钮颜色选择?