为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

富国沪深 2021-07-15 14:05:00
我正在尝试为计算机科学课程完成这个程序,但我遇到了这个错误你好特里斯坦维纳。您是 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 yearbirthdayYet = raw_input("Have you had your birthday yet? [1 for yes/2 for no]")#Ask if the user has had their birthdayage = 0def fullName (firstName, lastName):   outStr = firstName +" "+lastName    return outStrdef 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`
查看完整描述

2 回答

?
繁花不似锦

TA贡献1851条经验 获得超4个赞

finalMsg = printMsg(personName, personAge)

应该

finalMsg = printMsg(personName, userAge)

personAge是您用来获取人员年龄的函数。userAge是人的实际年龄。


查看完整回答
反对 回复 2021-07-28
?
芜湖不芜

TA贡献1796条经验 获得超7个赞

代替 …

finalMsg = printMsg(personName, personAge)

… 和 …

finalMsg = printMsg(personName, userAge)

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


查看完整回答
反对 回复 2021-07-28
  • 2 回答
  • 0 关注
  • 228 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信