Need help with python game program
2009-07-01 00:38:05 GMT
My problem is simple, is their a way to make a variable equal multiple numbers? Such as X = 5 through 10, and then the program makes x equal something random 5 through 10, or something similar.
Send Tutor mailing list submissions to
tutor <at> python.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-request <at> python.org
You can reach the person managing the list at
tutor-owner <at> python.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."
Today's Topics:
1. PYTHONPATH-corrected (Bob Rea)
2. Re: Needing Help (Bob Rea)
3. Re: PYTHONPATH-corrected (Steve Willoughby)
4. Re: Needing Help (Wayne)
5. Re: Needing Help (Bob Rea)
6. Re: Needing Help (Marc Tompkins)
----------------------------------------------------------------------
Message: 1
Date: Tue, 30 Jun 2009 14:33:27 -0400
From: Bob Rea <petard <at> petard.us>
To: tutor <at> python.org
Subject: [Tutor] PYTHONPATH-corrected
Message-ID: <200906301433.27455.petard <at> petard.us>
Content-Type: text/plain; charset="iso-8859-1"
In working my way through the book on python, I am working
in directories for chapers. Now I am on modules, and some
are reused in later chapters. I have set up a directory for
the modules. How do I add it to my PYTHONPATH?
I can use sys.path.append but that only lasts for the
session.
This is on a suse linux 10 box
--
Bob Rea
mailto:petard <at> petard.us
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
------------------------------
Message: 2
Date: Tue, 30 Jun 2009 14:06:01 -0400
From: Bob Rea <bob <at> telaugos.com>
To: tutor <at> python.org
Subject: Re: [Tutor] Needing Help
Message-ID: <200906301406.02104.bob <at> telaugos.com>
Content-Type: text/plain; charset="utf-8"
On Tue June 30 2009 1:17 pm, vishwajeet singh
<dextrous85 <at> gmail.com>wrote:
> You can put your script in pastebin
> http://python.pastebin.com/
> <http://python.pastebin.com/>I don't think any one will
> mind you pasting code in mail but pastebin makes it
> easier to read
I am making my way through _Making Use of Python_ by Rashi
Gupta. I am using Python 2.4.1
I have run into problems in a script, listed at
http://python.pastebin.com/m51bc3388
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?
Bob Rea
petard <at> petard.us
--
Bob Rea
mailto:gapetard <at> stsams.org
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
Where is Bill Stringfellow
now that we really need him?
------------------------------
Message: 3
Date: Tue, 30 Jun 2009 12:08:13 -0700
From: Steve Willoughby <steve <at> alchemy.com>
To: Bob Rea <petard <at> petard.us>
Cc: tutor <at> python.org
Subject: Re: [Tutor] PYTHONPATH-corrected
Message-ID: <20090630190813.GA65674 <at> dragon.alchemy.com>
Content-Type: text/plain; charset=us-ascii
On Tue, Jun 30, 2009 at 02:33:27PM -0400, Bob Rea wrote:
> In working my way through the book on python, I am working
> in directories for chapers. Now I am on modules, and some
> are reused in later chapters. I have set up a directory for
> the modules. How do I add it to my PYTHONPATH?
> I can use sys.path.append but that only lasts for the
> session.
You set the variable in your system's environment, which is
platform-dependent. For Linux, you'd typically put a line
in your ~/.profile or ~/.cshrc or ~/.login or ~/.bashrc or
whatever your shell uses per your account set up.
So, for example, in a bash/sh shell, you'd say:
export PYTHONPATH="/path/to/my/modules"
or for csh:
setenv PYTHONPATH "/path/to/my/modules"
Then starting the next time you log in, that will be set
in your environment for you.
> This is on a suse linux 10 box
>
> --
> Bob Rea
> mailto:petard <at> petard.us
> http://www.petard.us
> http://www.petard.us/blog
> http://www.petard.us/gallery
> _______________________________________________
> Tutor maillist - Tutor <at> python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Steve Willoughby | Using billion-dollar satellites
steve <at> alchemy.com | to hunt for Tupperware.
------------------------------
Message: 4
Date: Tue, 30 Jun 2009 14:27:34 -0500
From: Wayne <srilyk <at> gmail.com>
To: Bob Rea <bob <at> telaugos.com>
Cc: tutor <at> python.org
Subject: Re: [Tutor] Needing Help
Message-ID:
<333efb450906301227u76274a83x53ef42fdae41fead <at> mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"
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-0001.htm>
------------------------------
Message: 5
Date: Tue, 30 Jun 2009 15:27:17 -0400
From: Bob Rea <bob <at> telaugos.com>
To: Wayne <srilyk <at> gmail.com>
Cc: tutor <at> python.org
Subject: Re: [Tutor] Needing Help
Message-ID: <200906301527.20516.bob <at> telaugos.com>
Content-Type: text/plain; charset="utf-8"
On Tue June 30 2009 3:20 pm, you 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
Why doe sit work with a dob in 1943 and not with one in 1980
then, that's what really bugs me
--
Bob Rea
mailto:gapetard <at> stsams.org
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
Where is Bill Stringfellow
now that we really need him?
------------------------------
Message: 6
Date: Tue, 30 Jun 2009 12:45:00 -0700
From: Marc Tompkins <marc.tompkins <at> gmail.com>
To: Bob Rea <bob <at> telaugos.com>
Cc: tutor <at> python.org
Subject: Re: [Tutor] Needing Help
Message-ID:
<40af687b0906301245n3ffcc950k458e4bf629530965 <at> mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Tue, Jun 30, 2009 at 12:27 PM, Bob Rea <bob <at> telaugos.com> wrote:
> Why doe sit work with a dob in 1943 and not with one in 1980
> then, that's what really bugs me
>
Nothing to do with the year. Your birth month is BEFORE June; her birth
month is after.
--
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090630/0afb4e3c/attachment.htm>
------------------------------
_______________________________________________
Tutor maillist - Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
End of Tutor Digest, Vol 64, Issue 135
**************************************
--
You will be a winner today. Pick a fight with a four-year-old.
You should emulate your heros, but don't carry it too far. Especially
if they are dead.
_______________________________________________ Tutor maillist - Tutor <at> python.org http://mail.python.org/mailman/listinfo/tutor
RSS Feed