[Tutor] Needing Help
Wayne
srilyk at gmail.com
Tue Jun 30 21:27:34 CEST 2009
Oops, forgot my reply-to-all
On Tue, Jun 30, 2009 at 2:20 PM, Wayne <srilyk at gmail.com> wrote:
> On Tue, Jun 30, 2009 at 1:06 PM, Bob Rea <bob at telaugos.com> wrote:
>
>> <snip>
>> If I input my own name and dob, it works:
>> bob at gandalf:~/python/MakingUse/Chapter05> python code1.py
>> Enter your first name: Bob
>> Enter your last name: Rea
>> Enter your date of birth, mm-dd-yyyy: 03-05-1943
>> You can chose one of the following login names:
>> 1. BobR
>> 2. BobR53
>> 3. RBob43
>> 4. BRea66
>>
>> If I use the data listed in the book, it fails:
>> bob at gandalf:~/python/MakingUse/Chapter05> python code1.py
>> Enter your first name: Laura
>> Enter your last name: Jones
>> Enter your date of birth, mm-dd-yyyy: 12-24-1980
>> You can chose one of the following login names:
>> 1. LauraJ
>> 2. LauraJ2412
>> 3. JLaura80
>> Traceback (most recent call last):
>> File "code1.py", line 67, in ?
>> fourth=fname[0]+lname+ age_func()
>> TypeError: cannot concatenate 'str' and 'NoneType' objects
>>
>> What is going on here?
>>
>
> Well the first line after "Traceback" give you the line of code and the
> filename. Which happens to be code1.py line 67.
>
> TypeError is the type of error - specifically you tried to do something
> with incompatible types. In this case, adding together a string and
> NoneType.
>
> I'll do a little digging, but my guess is you have a problem with your
> age_func() not returning any value.
>
> HTH,
> Wayne
>
I was correct:def age_func():
age=cur_year-year-1
if month<cur_month or (month==cur_month and day<cur_day):
age=age+1
return str(age)
What happens if month is > cur_month AND it's not my birthday?
You don't return a value. But if you simply unindent the "return" value then
it should fix it:
def age_func():
age=cur_year-year-1
if month<cur_month or (month==cur_month and day<cur_day):
age=age+1
return str(age)
Now regardless of whether age is incremented, it will return a string.
HTH,
Wayne
--
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090630/fe4ba054/attachment.htm>
More information about the Tutor
mailing list