我在执行 python <function personAge at 0x101fe6050>

我正在尝试为计算机科学课程完成这个程序,但我遇到了这个错误


你好特里斯坦维纳。您是 0x101fe6050 岁的函数 personAge。


为什么我得到而不是年龄?


`#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`


富国沪深
浏览 238回答 2
2回答

繁花不似锦

finalMsg&nbsp;=&nbsp;printMsg(personName,&nbsp;personAge)应该finalMsg&nbsp;=&nbsp;printMsg(personName,&nbsp;userAge)personAge是您用来获取人员年龄的函数。userAge是人的实际年龄。

芜湖不芜

代替 …finalMsg&nbsp;=&nbsp;printMsg(personName,&nbsp;personAge)… 和 …finalMsg&nbsp;=&nbsp;printMsg(personName,&nbsp;userAge)记住personAge是一个函数而不是一个数字。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python