使用int输入创建和命名函数以供以后参考

时间:2019-01-08 16:44:05

标签: python-2.7 insert int main function-call

我正在尝试创建一个单独的函数,该函数需要一个整数输入。然后,我想通过仅使用我给它命名的名称调用它,将我创建的那个函数插入到主函数中。我一定对def()以及如何调用定义的函数有误解? 我在

下面添加了一个我想做的简化示例
#This would be the function I make to use later in main program
def functionforlater(value):
    if(value == 2):
       print("oranges")
    else:
       print("try again")


#This would be the main program
for(int x=0;x>3;x++):
    functionforlater(x)

# I've now come to the conclusion that the main program is the fault since there is no 
# such thing as for(int x=0;x>3;x++) in python they use "for x in range()" or xrange

#Solution for main program would be
for x in xrange(4):
    functionforlater(x)

1 个答案:

答案 0 :(得分:-1)

尝试这种方式:

def findASCI(value):
    if value == 2:
        print("oranges")
    else :
        print("try again")