簡體   English   中英

我在執行python時收到錯誤 <function personAge at 0x101fe6050> 而不是價值

[英]I am receiving an error when executing python <function personAge at 0x101fe6050> instead of the value

我正在嘗試完成計算機科學課程的該程序,但是我遇到了這個錯誤

你好,特里斯坦·維納(Tristan Wiener)。 您是功能人員,年齡為0x101fe6050歲。

為什么我要代替年齡?

`#This program calculates a users age while collecting the user's 
 #birth year, the user's first and last name, the current year
 #and whether the user has had their birthday yet.

 firstName = raw_input("Please enter your first name")#Get the first name
 lastName = raw_input("Please enter your last name")#Get the last name
 birthYear = int(input("What is your birth year?"))#Get the birth year
 currentYear = int(input("What is the current year?"))#Get the current year

birthdayYet = raw_input("Have you had your birthday yet? [1 for yes/2 for no]")
#Ask if the user has had their birthday
age = 0


def fullName (firstName, lastName):
   outStr = firstName +" "+lastName 
   return outStr

def personAge(birthYear, currentYear, birthdayYet):
   if birthdayYet == 1:
       print(currentYear - birthYear)

   if birthdayYet == 2:
      age = currentYear - birthYear - 1
      return str(age)

def printMsg(personName,personAge):
   return ("Hello" + " " + str(personName) + "." + " " + "You are" + " " + str(personAge) + " " + "years old.")

personName = fullName(firstName, lastName)
userAge = personAge(birthYear, currentYear, birthdayYet)
finalMsg = printMsg(personName, personAge)

print finalMsg`

更換...

finalMsg = printMsg(personName, personAge)

……與……

finalMsg = printMsg(personName, userAge)

記住personAge是一個函數而不是數字。

finalMsg = printMsg(personName, personAge)

應該

finalMsg = printMsg(personName, userAge)

personAge是用於獲取人員年齡的函數。 userAge是人的實際年齡。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM