我正在嘗試為計(jì)算機(jī)科學(xué)課程完成這個(gè)程序,但我遇到了這個(gè)錯(cuò)誤你好特里斯坦維納。您是 0x101fe6050 歲的函數(shù) 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貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
finalMsg = printMsg(personName, personAge)
應(yīng)該
finalMsg = printMsg(personName, userAge)
personAge
是您用來獲取人員年齡的函數(shù)。userAge
是人的實(shí)際年齡。

蕪湖不蕪
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
代替 …
finalMsg = printMsg(personName, personAge)
… 和 …
finalMsg = printMsg(personName, userAge)
記住personAge
是一個(gè)函數(shù)而不是一個(gè)數(shù)字。
添加回答
舉報(bào)
0/150
提交
取消