麻烦将参数从函数传递给函数python

时间:2016-04-08 01:50:21

标签: python-3.x

我一定是做错了,但我似乎无法弄明白。我试图将参数从一个函数传递到另一个函数但是在我的传递中我不断得到“某些东西未定义”,我无法弄清楚如何解决它。

def Information():
    #for x in range(0,3):
        #if x==0:
        #    print("first user")
        #elif x==1:
        #    print("Second user")
        #elif x==2:
        #    print("Third user")

        age=int(input("Please enter your age: "))
        height=int(input("Please enter your height in inches: "))
        eye=input("Please enter your eye color: ")
        First=input("Please enter your first name: ")
        Last=input("Please enter your last name: ")
        Street=input("Please enter your street address: ")
        City=input("Please enter your city: ")
        State=input("Please enter your state: ")
        Zip=int(input("Please enter your zip code: "))
        Infile=open('DataFile1.txt', 'a')
        Infile.write(str(age)+'\n')
        Infile.write(str(height)+'\n')
        Infile.write(eye+'\n')
        Infile.write(First+'\n')
        Infile.write(Last+'\n')
        Infile.write(str(Street)+'\n')
        Infile.write(City+'\n')
        Infile.write(State+'\n')        
        Infile.write(str(Zip)+'\n')
        Infile.close()                    
def Duplicate():
        info=[]
        with open("DataFile1.txt") as infile:
            for line in infile:
                    info.append(line)
        print(info)
        age2 = info[0]
        height2 = info[1]
        eye_color2 = info[2]
        first_name2 = info[3]
        last_name2 = info[4]
        street_address2 = info[5]
        city2 = info[6]
        state2 = info[7]
        zip_code2 = info[8]    
        return(age2,height2,eye_color2,first_name2,last_name2,street_address2,state2,zip_code2)
def Print(age,height,eye_color,first_name,last_name,street_address,city,state,zip_code):
        print(last_name, first_name)
        print(street_address)
        print(city, state, zip_code)
        print('Age: ', age)
        print('Height: ', height)
        print('Eye Color: ', eye_color)
def Main():
    Information()
    Duplicate()
    Print(age,height,eye_color,first_name,last_name,street_address,city,state,zip_code)


Main()

1 个答案:

答案 0 :(得分:0)

day views action 1: 01/01/2010 1 1 2: 01/01/2010 1 0 3: 01/01/2010 1 0 函数中,未定义Print()中的变量。以下代码将起到魔力。

Main()