List在代码中返回值none

时间:2017-10-05 12:59:35

标签: python list

创建变量罪命令让我以后回忆起来。

def initialise():
    global num
    global neg
    global pos
    global pos_list
    global neg_list
    global pos_sum
    global neg_sum
    pos_sum=0
    neg_sum=0
    num=1
    neg=0
    pos=0
    pos_list=[]
    neg_list=[]
    print("type your numbers")
    listing()

                                                                                                                                                            Allows the user to repeatedly list positive or negative numbers until they use '0'                    
def listing():
    global num
    global neg
    global pos
    global pos_list
    global neg_list
    global neg_sum
    global pos_sum
    num=1
    try:
        num=float(input())
        float(num)
        if num<0:
            neg_list.append(num)
            neg+=1
            neg_sum+=num
            listing()
        elif num>0:
            pos_list.append(num)
            pos+=1
            pos_sum+=um
            listing() 
        else:
            end()
    except ValueError:
        listing()

这会结束代码并创建一个简单的表供用户查看。(我总是像这样制作表格,因为我发现这种方式更简单,我知道有桌面功能,但我在学校,他们没有必要的图书馆

def end():
    global pos_list
    global neg_list
    global neg_sum
    global pos_sum
    global neg
    global pos
    pos_list=pos_list.sort()
    neg_list=neg_list.sort()
    total_sum=pos_sum+neg_sum
    print(" "*33,"Positive"," "*(50-len('positive')),"Negetive"," "*(50-len('negetive')))
    i1=0
    i2=0
    if len(pos_list)>=len(neg_list):
        count=len(pos_list)
    elif len(pos_list)<len(neg_list):
        count=len(neg_list)
    else:
        pass
    for x in range(count):
        print("number"," "*(50-len('number')-len(count)),pos_list[i1]," "*(50-len(pos_list[i1])),neg_list[i2]," "*(50-len(neg_list[i2])))
        i1+=1
        i2+=1
    print("amount of numbers"," "*(50-len('amount of numbers')),pos," "*(50-len(pos)),neg," "*50-len(neg))
    print("total"," "*(50-len('total')),pos_sum," "*(50-len(pos_sum)),neg_sum," "*(50-len(neg_sum)))

initialise()

问题:

NameError: global name 'pos_list' is not defined

发生在这里:

if len(pos_list)>=len(neg_list):

但我也可以看到这种情况发生在3-4行之后。

0 个答案:

没有答案