简体   繁体   中英

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

my code:

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.")

so without putting the code into cunks of functions it used to be fully functional, now all i get is a "Unsupported operand type(s) for +: 'function' and 'int' error" which is in the def counting function. im new to python and dont know why and whats happening. Thanks for any help :)

All the things you're using in your range are functions, not variables; you have to call (add call parens) them to get their value, changing:

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

to (with PEP8 spacing):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM