Python —为什么条件在一个函数中执行而在另一个函数中不执行?

我是Python初学者。我正在尝试编写一些基本代码来自动化一个简单但重复的工作过程,但是却为这个问题所困扰。

# Prior to the code block below, a csv file import would have created the a and ag variables with their respective numerical values.

high = list(range(66, 99))
mod = list(range(36, 65))
low = list(range(1,35))
verysiggap = list(range(61, 99))
siggap = list(range(31, 60))
nonsiggap = list(range(1, 30))

fco_output_list = []

def fco_block1(*args):
    if a in high and ag in high:
        print("Both a and ag are high!")
        fco_output_list.append("fco1")
    if a in high and ag in high and a-ag in nonsiggap:
        fco_output_list.append("foc2")

fco_block1(a, ag)

a_ag_combi_output = 0
a_ag_gap_output = 0

def fco_block2(*args):
    global a_ag_combi_output
    if a in high and ag in high:
        a_ag_combi_output = 0
    elif a in high and ag in low or ag in mod:
        a_ag_combi_output = 1
    elif a in mod and ag in low:
        a_ag_combi_output = 2
    elif ag in high and a in low or a in mod:
        a_ag_combi_output = 3
    elif ag in mod and a in low:
        a_ag_combi_output = 4
    elif a in low and ag in low:
        a_ag_combi_output = 5
    global a_ag_gap_output
    if a in high and ag in high and a-ag in nonsiggap:
        a_ag_gap_output = 1

fco_block2(a, ag)

# There are some simple print functions after the code above that tell me very clearly that fco_block2 executed without any issues. 

至于fco_block1的执行,没有错误消息,但是条件语句似乎没有执行。基于a和ag的导入值,fco_output_list应该已经由fco1和fco2填充,但事实并非如此。

为什么会这样呢?我觉得这很奇怪,尤其是当块1中的条件以与块2中的相应条件相同的方式措辞时,但是块2中的条件却被执行了,而块1中的条件却没有执行?

评论