我在执行python<function personAge at 0x101fe6050>而不是value时收到一个错误

2024-10-04 01:34:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图完成计算机科学课程的这个程序,但我被这个错误卡住了

你好,特里斯坦·维纳。您是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`

Tags: thenameinputageyourgetfirstnameyear
2条回答
finalMsg = printMsg(personName, personAge)

应该是

finalMsg = printMsg(personName, userAge)

personAge是用于获取人员年龄的函数userAge是人的实际年龄

替换

finalMsg = printMsg(personName, personAge)

…与

finalMsg = printMsg(personName, userAge)

记住personAge是一个函数而不是一个数字

相关问题 更多 >