Re: [Tutor] role playing game - help needed

2010-12-12 Thread David Hutto
On Sun, Dec 12, 2010 at 2:45 PM, David Hutto  wrote:
> On Sun, Dec 12, 2010 at 2:45 PM, David Hutto  wrote:
>> On Sun, Dec 12, 2010 at 2:44 PM, Walter Prins  wrote:
>>>
>>>
>>> On 12 December 2010 19:16, David Hutto  wrote:

  I recall you making a habit of being an
 asshole(pystats should ring a bell, thanks for giving me the credit
 for inspiration...bitch)
>>>
>>> Rudeness objection.  Ad-hominem objection.
>>>
>>> Come on, this is not kindergarten.


But steven likes to be the smartest kindergartner, show his holier
than thou posts since he likes to recall others posts. Look ma what I
can do.

 We all have our foibles, and although
>>> I'd agree the tone around here occasionally leaves something to be desired,
>>> you just lower yourself to the same level and make matters worse if you
>>> resort to this type of name-calling.   Let's stick to objectively (as far as
>>> possible) critiquing and considering the points raised.
>>>
>>> Walter
>>>
>>  He started it Mama!
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-12 Thread David Hutto
On Sun, Dec 12, 2010 at 2:45 PM, David Hutto  wrote:
> On Sun, Dec 12, 2010 at 2:44 PM, Walter Prins  wrote:
>>
>>
>> On 12 December 2010 19:16, David Hutto  wrote:
>>>
>>>  I recall you making a habit of being an
>>> asshole(pystats should ring a bell, thanks for giving me the credit
>>> for inspiration...bitch)
>>
>> Rudeness objection.  Ad-hominem objection.
>>
>> Come on, this is not kindergarten.  We all have our foibles, and although
>> I'd agree the tone around here occasionally leaves something to be desired,
>> you just lower yourself to the same level and make matters worse if you
>> resort to this type of name-calling.   Let's stick to objectively (as far as
>> possible) critiquing and considering the points raised.
>>
>> Walter
>>
>  He started it Mama!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-12 Thread David Hutto
On Sun, Dec 12, 2010 at 2:44 PM, Walter Prins  wrote:
>
>
> On 12 December 2010 19:16, David Hutto  wrote:
>>
>>  I recall you making a habit of being an
>> asshole(pystats should ring a bell, thanks for giving me the credit
>> for inspiration...bitch)
>
> Rudeness objection.  Ad-hominem objection.
>
> Come on, this is not kindergarten.  We all have our foibles, and although
> I'd agree the tone around here occasionally leaves something to be desired,
> you just lower yourself to the same level and make matters worse if you
> resort to this type of name-calling.   Let's stick to objectively (as far as
> possible) critiquing and considering the points raised.
>
> Walter
>
 He started it!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-12 Thread Walter Prins
On 12 December 2010 19:16, David Hutto  wrote:

>  I recall you making a habit of being an
> asshole(pystats should ring a bell, thanks for giving me the credit
> for inspiration...bitch)
>

Rudeness objection.  Ad-hominem objection.

Come on, this is not kindergarten.  We all have our foibles, and although
I'd agree the tone around here occasionally leaves something to be desired,
you just lower yourself to the same level and make matters worse if you
resort to this type of name-calling.   Let's stick to objectively (as far as
possible) critiquing and considering the points raised.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-12 Thread David Hutto
On Sun, Dec 12, 2010 at 2:16 PM, David Hutto  wrote:
> On Sat, Dec 11, 2010 at 10:39 PM, Steven D'Aprano  wrote:
>> David Hutto wrote:
>>>
>>> On Sat, Dec 11, 2010 at 11:54 AM, Lie Ryan  wrote:

 On 12/07/10 23:37, Robert Sjöblom wrote:
>
> I've been told to use input() if I know that I'll only get integers,
> and raw_input() for "everything."

 That is a bad piece of advice. You should only use input() when you can
 fully trust whoever doing the input (i.e. you).
>>>
>>> Who uses the crap we, as noobies produce? It's pie in the sky
>>> mentality. We design it because WE want it and WE(individually) use
>>> it.
>>
>> Do you want to learn good habits or learn bad habits? I think we've seen
>> plenty of evidence on this mailing list that you have little interest in
>> learning good habits, but actively defend your right learn bad habits.
>
> You define a good habit as making the code impossible for someone just
> learning to use,
> and you call my habits bad.. I recall you making a habit of being an
> asshole(pystats should ring a bell, thanks for giving me the credit
> for inspiration...bitch)
>
>
>
>>
>> There are plenty of people who do the same. They're harmless and even
>> pathetically amusing as newbies,

Said the pathetically amusing pro.

 and then they get a job working as a
>> professional programmer, and end up writing crappy, bug-addled code filled

As your ignorant ass did when you first started(maybe no email
evidence, but just an educated guess)

>> with the sort of n00b errors that we've been warning about. Bug-addled code
>> with *real* consequences.
>
> Yeah, we call that YOUR mistakes being pointed out later in life due
> to experience.
> 20/20 hindsight is great ain't it poindexter?
>
>>
>> Command injection bugs are hugely common in the real world. At least four of
>> the 25 most common security bugs in *professional* software are in my
>> opinion varieties of the command injection flaw, and one of those is the
>> SECOND most common flaw:
>>
>> SQL injection attack #2 most common
>> Unrestricted upload of dangerous files #8 most common
>> OS command injection #9 most common
>> PHP file inclusion attack #13 most common
>
> Injection is only relevant in non-personal code.
>
>
>>
>> http://cwe.mitre.org/top25/
>>
>> OS command injection is *exactly* the sort of thing we're warning about.
>>
>> Feel free to continue learning bad habits, but please stop trying to
>> encourage others to do the same.
>
> I didn't encourage a bad habit, I encouraged development of a problem
> defined by the client and a solution developed byu the programmer.
>
> The only bad habit around here, is your condescending nature.
>
>
>>
>>
>> --
>> Steven
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>


And if you do look at the emails, yes i was hostile at the
beginning(I've learned to ignore bitches like you), because of
attitudes like yours. And if you also look, everytime I tried to help
point a fellow noob in the right direction, you came in and said how
ignorant I was for trying to help(thanks alot, from them and me).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-12 Thread David Hutto
On Sat, Dec 11, 2010 at 10:39 PM, Steven D'Aprano  wrote:
> David Hutto wrote:
>>
>> On Sat, Dec 11, 2010 at 11:54 AM, Lie Ryan  wrote:
>>>
>>> On 12/07/10 23:37, Robert Sjöblom wrote:

 I've been told to use input() if I know that I'll only get integers,
 and raw_input() for "everything."
>>>
>>> That is a bad piece of advice. You should only use input() when you can
>>> fully trust whoever doing the input (i.e. you).
>>
>> Who uses the crap we, as noobies produce? It's pie in the sky
>> mentality. We design it because WE want it and WE(individually) use
>> it.
>
> Do you want to learn good habits or learn bad habits? I think we've seen
> plenty of evidence on this mailing list that you have little interest in
> learning good habits, but actively defend your right learn bad habits.

You define a good habit as making the code impossible for someone just
learning to use,
and you call my habits bad.. I recall you making a habit of being an
asshole(pystats should ring a bell, thanks for giving me the credit
for inspiration...bitch)



>
> There are plenty of people who do the same. They're harmless and even
> pathetically amusing as newbies, and then they get a job working as a
> professional programmer, and end up writing crappy, bug-addled code filled
> with the sort of n00b errors that we've been warning about. Bug-addled code
> with *real* consequences.

Yeah, we call that YOUR mistakes being pointed out later in life due
to experience.
20/20 hindsight is great ain't it poindexter?

>
> Command injection bugs are hugely common in the real world. At least four of
> the 25 most common security bugs in *professional* software are in my
> opinion varieties of the command injection flaw, and one of those is the
> SECOND most common flaw:
>
> SQL injection attack #2 most common
> Unrestricted upload of dangerous files #8 most common
> OS command injection #9 most common
> PHP file inclusion attack #13 most common

Injection is only relevant in non-personal code.


>
> http://cwe.mitre.org/top25/
>
> OS command injection is *exactly* the sort of thing we're warning about.
>
> Feel free to continue learning bad habits, but please stop trying to
> encourage others to do the same.

I didn't encourage a bad habit, I encouraged development of a problem
defined by the client and a solution developed byu the programmer.

The only bad habit around here, is your condescending nature.


>
>
> --
> Steven
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-12 Thread Alan Gauld

"David Hutto"  wrote

> That is a bad piece of advice. You should only use input() when 
> you can

> fully trust whoever doing the input (i.e. you).

Who uses the crap we, as noobies produce?


Hopefully you do.
And can you really be absolutely sure you won't accidentally
type a dangerous command into an input prompt?
I once accidentally deleted all the files on my Unix workstation
by thinking I was in a subdirectory when I was at the root folder
as administrator It took me several hours to recover the bulk
of my files using the raw shell commands and a nwetwork
connection to my colleage's Sun box.

The point is that it's nearly as easy to use good practice as it
is to use bad practice so you might as well get used to doing
it the safe way. Then you are protected, even from yourself.


It's pie in the sky mentality. We design it because WE
want it and WE(individually) use it.


But if it works for you it may well work for somebody else,
who, when they see it, want a copy. That's how the vast majority
of amateur written software starts off, then it becomes
shareware or opensource and starts getting copied on.
And if it has insecure code in, people get bitten. Now, you
can argue its their own fault for using "opensource" code,
but they won't see it that way.

One of the most widely distributed programs that I've written
(privately) was something I did when first learning Windows
programming with Delphi - literally the second Windows
program I ever wrote. 15 years lqater I still get the occasional
email from somebody who has found a copy and wants to use it!
It was a learning excercise for my own amusement, I lent it
to a friend, who lent it to a friend who asked for some
tweaks, etc... There are probably several hundred users now.

And remember that Linux started out as a personal learning
exercise for Linus Torvalds while a student, he didn't set out
to challlenge Microsoft, it was just a bit of a fun thing to do.

Software that does something useful has a habit of proliferating,
even when written by noobies. Get into the habit of doing things
well and that will be a good thing of which you can be proud..

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-11 Thread Steven D'Aprano

David Hutto wrote:

On Sat, Dec 11, 2010 at 11:54 AM, Lie Ryan  wrote:

On 12/07/10 23:37, Robert Sjöblom wrote:

I've been told to use input() if I know that I'll only get integers,
and raw_input() for "everything."

That is a bad piece of advice. You should only use input() when you can
fully trust whoever doing the input (i.e. you).


Who uses the crap we, as noobies produce? It's pie in the sky
mentality. We design it because WE want it and WE(individually) use
it.


Do you want to learn good habits or learn bad habits? I think we've seen 
plenty of evidence on this mailing list that you have little interest in 
learning good habits, but actively defend your right learn bad habits.


There are plenty of people who do the same. They're harmless and even 
pathetically amusing as newbies, and then they get a job working as a 
professional programmer, and end up writing crappy, bug-addled code 
filled with the sort of n00b errors that we've been warning about. 
Bug-addled code with *real* consequences.


Command injection bugs are hugely common in the real world. At least 
four of the 25 most common security bugs in *professional* software are 
in my opinion varieties of the command injection flaw, and one of those 
is the SECOND most common flaw:


SQL injection attack #2 most common
Unrestricted upload of dangerous files #8 most common
OS command injection #9 most common
PHP file inclusion attack #13 most common

http://cwe.mitre.org/top25/

OS command injection is *exactly* the sort of thing we're warning about.

Feel free to continue learning bad habits, but please stop trying to 
encourage others to do the same.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-11 Thread David Hutto
On Sat, Dec 11, 2010 at 11:54 AM, Lie Ryan  wrote:
> On 12/07/10 23:37, Robert Sjöblom wrote:
>> I've been told to use input() if I know that I'll only get integers,
>> and raw_input() for "everything."
>
> That is a bad piece of advice. You should only use input() when you can
> fully trust whoever doing the input (i.e. you).

Who uses the crap we, as noobies produce? It's pie in the sky
mentality. We design it because WE want it and WE(individually) use
it.

 input() can accept any
> python expressions, and this means the user can potentially execute
> malicious code as well.
>
 import subprocess
 input("input: ")
> input: subprocess.Popen(('ping', 'www.google.com'))
> 
 PING www.l.google.com (66.102.11.104) 56(84) bytes of data.
> 64 bytes from syd01s01-in-f104.1e100.net (66.102.11.104): icmp_req=1
> ttl=57 time=18.5 ms
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-11 Thread Lie Ryan
On 12/07/10 23:37, Robert Sjöblom wrote:
> I've been told to use input() if I know that I'll only get integers,
> and raw_input() for "everything."

That is a bad piece of advice. You should only use input() when you can
fully trust whoever doing the input (i.e. you). input() can accept any
python expressions, and this means the user can potentially execute
malicious code as well.

>>> import subprocess
>>> input("input: ")
input: subprocess.Popen(('ping', 'www.google.com'))

>>> PING www.l.google.com (66.102.11.104) 56(84) bytes of data.
64 bytes from syd01s01-in-f104.1e100.net (66.102.11.104): icmp_req=1
ttl=57 time=18.5 ms

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-10 Thread ALAN GAULD


Thanks again Alan.  Much clearer now.  One final part I don't understand.
> 
 "%d is the result of %d + %d" % (6+7,6,7)
> 
>I understand (I think) the 6+7 part but why the ,6,7 after that.  I could 
>see how either '6+7' or '6,7' would be the correct format but not both.

The format string has 3 percent markers - all numbers.
It is therefore expecting 3 values, so I have to give it them.
The first marker gets 6+7, ie 13. The second gets 6 
the third 7...

Look at the first example in the loops topic in my tutorial.
It uses variables in the same way rather than literal values, 
that might make it more obvious. Maybe :-)
 HTH,

Alan G.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-09 Thread ALAN GAULD
Can you explain this in a little more detail?
>
>
sure.

 
>
>for name in attributes.keys():
>  attributes[name] = int( input("How many points do you want to assign to %s " 
> % 
>name) )
> 
>Where did you get 'name' from?  
>

I made it up. The for loop takes the form

for  in :
  

where the bits in <> are provided by the programmer.
name was just a "meaningful" variable name that I chose.

> What does the % do and how does it work inside the 
> quotation marks as opposed to outside?  

This is called string formatting. Actually in Python 3 there is a new way of 
doing this but the older style, like this, still works.

Basically within the string we insert percent signs followed by 
a special letter to indicate the type of data we want to insert into 
the string. %s means a string, %d a decimal number, %f a floating 
point number etc.

The % immediately after the string is a separator preceding the 
values to be inserted into the string

Try it at the >>> prompt:

>>> "%d is a number" % 6
6 is a number
>>> "%d is the result of %d + %d" % (6+7,6,7)
13 is the result of 6 + 7
>>> "My name is %s" % "Alan"
My name is Alan

Someone else might show you the v3 way using the 
new string.format() operator


HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-08 Thread Alan Gauld


"Al Stern"  wrote


Anyway, I finally finished the program.  I am sure it isn't the most
efficient code and I suspect I should have used the 'while' loop 
earlier,


Some things to think about below.

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 
0}

MAX_POINTS = int(30)
keys = attributes.keys()
values = attributes.values()


you don't need keys and values as variables because you can always
fetch them from atttributes as needed.


list (values)


This converts values into a list, which it already is, then throws it 
away.

I suspect you think its doing something else?.

attributes["strength"] = int(input("\nHow many points do you want to 
assign

to strength?: "))
attributes["health"] = int(input("\nHow many points do you want to 
assign to

health?: "))
attributes["wisdom"] = int(input("\nHow many points do you want to 
assign to

wisdom?: "))
attributes["dexterity"] = int(input("\nHow many points do you want 
to assign

to dexterity?: "))


One of the advantages of using a dict is that you can use a loop here
and thus easily extend your data in the futire without changing the
input/output code:

for name in attributes.keys():
   attributes[name] = int( input("How many points do you want to 
assign to %s " % name) )




#point allocation
point_total = 0
for val in values:
 point_total += val


point_total = sum( attributes.values() )




print ("\nThis is how you have chosen to allocate your 30 points.")
print ("\nStrength:",(attributes["strength"]))
print ("Health:", (attributes["health"]))
print ("Wisdom:", (attributes["wisdom"]))
print ("Dexterity:", (attributes["dexterity"]))


And as above this can be a loop:

for name in attributes.keys():
   print("\n", name, ":", attributes[name] )


available_points = (MAX_POINTS) - (point_total)


No need for any of the parentheses here


while point_total != "":


You are comparing point_total to a string, but point_total is a 
number.

You need to be careful about keeping your data types consistent.


   if point_total > 30:
 print ("\nYou have gone over your alloted 30 points.")
 print ("Please re-enter your choices. ")




 #point allocation
 point_total = 0
 for val in values:
   point_total += val


again, use sum()

 print ("\nThis is how you have chosen to allocate your 30 
points.")

 print ("\nStrength:",(attributes["strength"]))
 print ("Health:", (attributes["health"]))
 print ("Wisdom:", (attributes["wisdom"]))
 print ("Dexterity:", (attributes["dexterity"]))
 available_points = (MAX_POINTS) - (point_total)
 continue
   else:
 break


The logic here could be simplified into

while point_total > 30:


print ("\nYou have", available_points, "points left.")
print ("\nSince you have points left over, you may reallocate your 
points or

begin your quest.")
choice = int(input("\nTo reallocate, press 1.  To begin, press 2: 
"))

while choice != "":


Again comparing to a string but you have made choice an integer


 if choice == 1:
   print ("Please re-enter your choices. ")
   attributes["strength"] = int(input("\nHow many points do you want 
to

assign to strength?: "))
   attributes["health"] = int(input("\nHow many points do you want 
to

assign to health?: "))
   attributes["wisdom"] = int(input("\nHow many points do you want 
to

assign to wisdom?: "))
   attributes["dexterity"] = int(input("\nHow many points do you 
want to

assign to dexterity?: "))

   #point allocation
   point_total = 0
   for val in values:
 point_total += val


Note, you haven't actually assigned anything to values since the user
entered the new data. This is another reason it would be better to not
have the variable, just get values directly from attributes on demand.


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-08 Thread Al Stern
Peter, Thanks for the advice as to how to use numbers.  I had learned this
before but the example in the documentation didn't use 'int' so I thought I
didn't need to when using dictionary values.

Anyway, I finally finished the program.  I am sure it isn't the most
efficient code and I suspect I should have used the 'while' loop earlier,
but the bottom line is it seems to work.  I will paste what I came up with
in case anyone is interested.

Thanks again to everyone.  I couldn't have done it wothout you.

-Al

# character creator / role playing game
# have 30 total points to work with
# set variables
attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = int(30)
keys = attributes.keys()
values = attributes.values()

list (values)
print("""
Welcome to Quest.  The goal of the game is to help our hero achieve his
mission.
He will need strength, health, wisdom and dexterity to survive.
You will have 30 points to 'spend' on these attributes.
Use them wisely.  His life depends on it.
"""
)

attributes["strength"] = int(input("\nHow many points do you want to assign
to strength?: "))
attributes["health"] = int(input("\nHow many points do you want to assign to
health?: "))
attributes["wisdom"] = int(input("\nHow many points do you want to assign to
wisdom?: "))
attributes["dexterity"] = int(input("\nHow many points do you want to assign
to dexterity?: "))

#point allocation
point_total = 0
for val in values:
  point_total += val
print ("\nThis is how you have chosen to allocate your 30 points.")
print ("\nStrength:",(attributes["strength"]))
print ("Health:", (attributes["health"]))
print ("Wisdom:", (attributes["wisdom"]))
print ("Dexterity:", (attributes["dexterity"]))
available_points = (MAX_POINTS) - (point_total)
while point_total != "":
if point_total > 30:
  print ("\nYou have gone over your alloted 30 points.")
  print ("Please re-enter your choices. ")
  attributes["strength"] = int(input("\nHow many points do you want to
assign to strength?: "))
  attributes["health"] = int(input("\nHow many points do you want to
assign to health?: "))
  attributes["wisdom"] = int(input("\nHow many points do you want to
assign to wisdom?: "))
  attributes["dexterity"] = int(input("\nHow many points do you want to
assign to dexterity?: "))

  #point allocation
  point_total = 0
  for val in values:
point_total += val
  print ("\nThis is how you have chosen to allocate your 30 points.")
  print ("\nStrength:",(attributes["strength"]))
  print ("Health:", (attributes["health"]))
  print ("Wisdom:", (attributes["wisdom"]))
  print ("Dexterity:", (attributes["dexterity"]))
  available_points = (MAX_POINTS) - (point_total)
  continue
else:
  break
print ("\nYou have", available_points, "points left.")
print ("\nSince you have points left over, you may reallocate your points or
begin your quest.")
choice = int(input("\nTo reallocate, press 1.  To begin, press 2: "))
while choice != "":
  if choice == 1:
print ("Please re-enter your choices. ")
attributes["strength"] = int(input("\nHow many points do you want to
assign to strength?: "))
attributes["health"] = int(input("\nHow many points do you want to
assign to health?: "))
attributes["wisdom"] = int(input("\nHow many points do you want to
assign to wisdom?: "))
attributes["dexterity"] = int(input("\nHow many points do you want to
assign to dexterity?: "))

#point allocation
point_total = 0
for val in values:
  point_total += val
print ("\nThis is how you have chosen to allocate your 30 points.")
print ("\nStrength:",(attributes["strength"]))
print ("Health:", (attributes["health"]))
print ("Wisdom:", (attributes["wisdom"]))
print ("Dexterity:", (attributes["dexterity"]))
available_points = (MAX_POINTS) - (point_total)
print ("\nYou have", available_points, "points left.")
print ("\nSince you have points left over, you may reallocate your
points or begin your quest.")
choice = int(input("\nTo reallocate, press 1.  To begin, press 2: "))
  elif choice == 2:
break
  else:
continue


print ("You are now ready to begin your quest.  Good luck.")
input ("\n\nPress the enter key to continue.\n")




On Tue, Dec 7, 2010 at 5:29 PM, Peter Otten <__pete...@web.de> wrote:

> Al Stern wrote:
>
> > I used the following code and got the following error.
>
> The result of input is always a string.
>
> > attributes["strength"] = input("\nHow many points do you want to assign
> to
> > strength?: ")
>
> Say you type 42 when you run your script. Then the above assignment is
> effectively
>
> attributes["strength"] = "42"
>
> and when you loop over the values you try to add a string to an integer
> which is what Python complains about:
>
> >>> 42 + "42"
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>
> To get an integer you have t

Re: [Tutor] role playing game - help needed

2010-12-07 Thread Peter Otten
Al Stern wrote:

> I used the following code and got the following error.

The result of input is always a string. 
 
> attributes["strength"] = input("\nHow many points do you want to assign to
> strength?: ")

Say you type 42 when you run your script. Then the above assignment is 
effectively

attributes["strength"] = "42"

and when you loop over the values you try to add a string to an integer 
which is what Python complains about:

>>> 42 + "42"
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for +: 'int' and 'str'

To get an integer you have to convert the string explicitly:

>>> 42 + int("42")
84

The best place to do that is as early as possible, even before you put the 
value into the dictionary:

attributes["strength"] = int(input(...))

(In a real application you'd guard against values that cannot be converted 
to integers)

> #point allocation
> point_total = 0
> for val in values:
> point_total += val
> print (point_total)
> 
> and get this error...
> 
> Traceback (most recent call last):
> File "C:\Users\Public\Documents\My Python programs\role_playing_game1.py",
> line 26, in 
> point_total += val
> TypeError: unsupported operand type(s) for +=: 'int' and 'str'


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Adam Bark

On 07/12/10 22:10, Al Stern wrote:

Tried to use the documentation but still getting the errors...
The 1st one has to do with the available_points
# set variables
attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = 30
available_points = MAX_POINTS - attributes.values()
keys = attributes.keys()
values = attributes.values()
this is the error i'm getting...
Traceback (most recent call last):
  File "C:\Users\Public\Documents\My Python 
programs\role_playing_game1.py", line 8, in 

available_points = MAX_POINTS - attributes.values()
TypeError: unsupported operand type(s) for -: 'int' and 'dict_values'
I know using attributes.values here isn't correct but I can't figure 
out how to put the sum of the values into that equation.


Using attributes.values is fine. There is a built in function for 
summing all the values in a sequence, it's called "sum".


HTH
Adam.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Al Stern
Tried to use the documentation but still getting the errors...

The 1st one has to do with the available_points

# set variables
attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = 30
available_points = MAX_POINTS - attributes.values()
keys = attributes.keys()
values = attributes.values()

this is the error i'm getting...

Traceback (most recent call last):
  File "C:\Users\Public\Documents\My Python programs\role_playing_game1.py",
line 8, in 
available_points = MAX_POINTS - attributes.values()
TypeError: unsupported operand type(s) for -: 'int' and 'dict_values'

I know using attributes.values here isn't correct but I can't figure out how
to put the sum of the values into that equation.

I looked up this part f the docs...
http://docs.python.org/py3k/library/stdtypes.html?highlight=values#dict.values
and tried to copy the format into my program. I am attempting to get the
total of the values of everything in my dictionary.   Not sure what is
different between my 'attributes' dictionary and the 'dishes' dictionary
they use.  I used the following code and got the following error.

attributes["strength"] = input("\nHow many points do you want to assign to
strength?: ")

#point allocation
point_total = 0
for val in values:
  point_total += val
  print (point_total)

and get this error...

Traceback (most recent call last):
  File "C:\Users\Public\Documents\My Python programs\role_playing_game1.py",
line 26, in 
point_total += val
TypeError: unsupported operand type(s) for +=: 'int' and 'str'




On Tue, Dec 7, 2010 at 10:06 AM, Peter Otten <__pete...@web.de> wrote:

> Al Stern wrote:
>
> > Apologies for all my questions.  Up to this point I have been able to
> work
> > out most of the challenges but I seem to have hit a wall.  Can't seem to
> > make any progress and completely frustrated.
> >
> > I looked at the 11/21 discussion.  From the documentation, I realized I
> > needed to set the variables to view the keys and values.  Getting an
> error
> > though.
> >
> > attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
> > MAX_POINTS = 30
> > keys = attributes.viewkeys()
> > values = attributes.viewvalues()
> >
> > Traceback (most recent call last):
> >   File "C:\Users\Public\Documents\My Python
> >   programs\role_playing_game1.py",
> > line 8, in 
> > keys = attributes.viewkeys()
> > AttributeError: 'dict' object has no attribute 'viewkeys'
>
> The dictionary methods you are looking for are called keys() and values()
> not viewkeys() or viewvalues(). They do return view objects which may be
> causing the confusion. Have a look at the documentation at
>
> http://docs.python.org/dev/py3k/library/stdtypes.html#dictionary-view-
> objects
>
> which shows a simple example.
> By the way you, can use the interactive interpreter to find out what
> attributes an object has to offer:
>
> $ python3
> Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> d = {"a": 1, "b": 2}
> >>> dir(d)
> ['__class__', '__contains__', '__delattr__', '__delitem__', '__doc__',
> '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
> '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
> '__lt__',
> '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
> '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__',
> 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem',
> 'setdefault', 'update', 'values']
>
> Peter
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Peter Otten
Al Stern wrote:

> Apologies for all my questions.  Up to this point I have been able to work
> out most of the challenges but I seem to have hit a wall.  Can't seem to
> make any progress and completely frustrated.
> 
> I looked at the 11/21 discussion.  From the documentation, I realized I
> needed to set the variables to view the keys and values.  Getting an error
> though.
> 
> attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
> MAX_POINTS = 30
> keys = attributes.viewkeys()
> values = attributes.viewvalues()
> 
> Traceback (most recent call last):
>   File "C:\Users\Public\Documents\My Python
>   programs\role_playing_game1.py",
> line 8, in 
> keys = attributes.viewkeys()
> AttributeError: 'dict' object has no attribute 'viewkeys'

The dictionary methods you are looking for are called keys() and values() 
not viewkeys() or viewvalues(). They do return view objects which may be 
causing the confusion. Have a look at the documentation at

http://docs.python.org/dev/py3k/library/stdtypes.html#dictionary-view-
objects

which shows a simple example. 
By the way you, can use the interactive interpreter to find out what 
attributes an object has to offer:

$ python3
Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {"a": 1, "b": 2}
>>> dir(d)
['__class__', '__contains__', '__delattr__', '__delitem__', '__doc__', 
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', 
'__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', 
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 
'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 
'setdefault', 'update', 'values']

Peter

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Al Stern
Apologies for all my questions.  Up to this point I have been able to work
out most of the challenges but I seem to have hit a wall.  Can't seem to
make any progress and completely frustrated.

I looked at the 11/21 discussion.  From the documentation, I realized I
needed to set the variables to view the keys and values.  Getting an error
though.

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = 30
keys = attributes.viewkeys()
values = attributes.viewvalues()

Traceback (most recent call last):
  File "C:\Users\Public\Documents\My Python programs\role_playing_game1.py",
line 8, in 
keys = attributes.viewkeys()
AttributeError: 'dict' object has no attribute 'viewkeys'




On Tue, Dec 7, 2010 at 3:44 AM, Alan Gauld wrote:

>
> "Al Stern"  wrote
>
>  attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
>> MAX_POINTS = 30
>>
>> How do I set the variable for available_points?
>>
>> available_points = MAX_POINTS - (not sure what goes here)
>>
>
> Check the mail from Robert Sjoblom, he gives you the necessary clues.
> You can check the archive a few weeks back(21st Nov) for his question
> too and get some alternative options and discussion.
>
>
> attributes["strength"] = input("\nHow many points do you want to assign to
>> strength?: ")
>>
>> Please let me know if this isn't advisable.  It seems to work on the
>> surface.
>>
>
> Close, but remember that input() returns a string. You need numbers
> so you need to convert strings to integers.
>
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Peter Otten
Robert Sjöblom wrote:

>> Close, but remember that input() returns a string. You need numbers
>> so you need to convert strings to integers.
> 
> Actually, input() only accept integers, consider the following:
 input("input: ")
> input: d
> 
> Traceback (most recent call last):
> File "", line 1, in 
> input("input: ")
> File "", line 1, in 
> NameError: name 'd' is not defined

You are using Python 2.x where raw_input() was used to enter strings and 
input() behaved like

eval(raw_input())

From the above follows that input() in 2.x accepts arbitrary Python 
expressions:

Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = 42
>>> input()
d
42
>>> input()
d**2
1764
>>> input()
"*".join([str(d)]*5)
'42*42*42*42*42'

I think I drove the point home ;)

input() in Python 3.x on the other hand is similar to 2.x's raw_input():

Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> input()
d
'd'
>>> input()
"*".join([str(d)]*5)
'"*".join([str(d)]*5)'

Peter

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Robert Sjöblom
>> attributes["strength"] = input("\nHow many points do you want to
>> assign to
>> strength?: ")
>>
>> Please let me know if this isn't advisable.  It seems to work on the
>> surface.
>
> Close, but remember that input() returns a string. You need numbers
> so you need to convert strings to integers.

Actually, input() only accept integers, consider the following:
>>> input("input: ")
input: d

Traceback (most recent call last):
  File "", line 1, in 
input("input: ")
  File "", line 1, in 
NameError: name 'd' is not defined

if you assign d to an integer, input() will accept it, however:
>>> d = 7
>>> input("input: ")
input: d
7

>>> input("input: ")
input: 7
7

>>> help(input)
Help on built-in function input in module __builtin__:

input(...)
input([prompt]) -> value

Equivalent to eval(raw_input(prompt)).

I've been told to use input() if I know that I'll only get integers,
and raw_input() for "everything." Would you say it's better to use
raw_input() for everything and convert as necessary?

best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Robert Sjöblom
>> Thanks for the advice.  I think I have the dictionary function set up right
>>> now although I'm still not clear why it is better than the list.
>>>
>>> attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
>>>
>>
>> Consider where you want to update the points for "health"
>>
>> Using two lists you need to loop over the keys list to find the index
>> of "health" then access the values list to set the points. Something
>> like this:
>>
>> for x in range(len(keys)):
>>   if keys[x] == "health":
>>   values[x] = newValue
>>
>> With a dictionary you just need to do
>>
>> attributes["health"] = newValue
>>
>> That's a lot less typing and will be faster performance too.
>> I'd also say its a lot easier to see whats happening - its more readable.
[snip]
>
> Ok.  I think I am starting to get it but still not sure how to separate the
> value from the key.  Once I have this...
>
> attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
> MAX_POINTS = 30
>
> How do I set the variable for available_points?
>
> available_points = MAX_POINTS - (not sure what goes here)
attributes.values() will give you a list of the values inside the
attributes dictionary (remember, dictionaries work by key: value
pairs). sum() won't work on a dictionary that contains both strings
and integers, . If you only use integers in your values, the list will
only contain integers, and so you can easily use sum() on it.

> I am pretty sure I will change the values by something like this...
>
> attributes["strength"] = input("\nHow many points do you want to assign to
> strength?: ")
>
> Please let me know if this isn't advisable.  It seems to work on the
> surface.
That's how you do it.

best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-07 Thread Alan Gauld


"Al Stern"  wrote

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 
0}

MAX_POINTS = 30

How do I set the variable for available_points?

available_points = MAX_POINTS - (not sure what goes here)


Check the mail from Robert Sjoblom, he gives you the necessary clues.
You can check the archive a few weeks back(21st Nov) for his question
too and get some alternative options and discussion.

attributes["strength"] = input("\nHow many points do you want to 
assign to

strength?: ")

Please let me know if this isn't advisable.  It seems to work on the
surface.


Close, but remember that input() returns a string. You need numbers
so you need to convert strings to integers.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-06 Thread Al Stern
Ok.  I think I am starting to get it but still not sure how to separate the
value from the key.  Once I have this...

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = 30

How do I set the variable for available_points?

available_points = MAX_POINTS - (not sure what goes here)

I am pretty sure I will change the values by something like this...

attributes["strength"] = input("\nHow many points do you want to assign to
strength?: ")

Please let me know if this isn't advisable.  It seems to work on the
surface.

On Mon, Dec 6, 2010 at 1:16 PM, Alan Gauld wrote:

>
> "Al Stern"  wrote
>
>
> Thanks for the advice.  I think I have the dictionary function set up right
>> now although I'm still not clear why it is better than the list.
>>
>> attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
>>
>
> Consider where you want to update the points for "health"
>
> Using two lists you need to loop over the keys list to find the index
> of "health" then access the values list to set the points. Something
> like this:
>
> for x in range(len(keys)):
>   if keys[x] == "health":
>   values[x] = newValue
>
> With a dictionary you just need to do
>
> attributes["health"] = newValue
>
> That's a lot less typing and will be faster performance too.
> I'd also say its a lot easier to see whats happening - its more readable.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-06 Thread Alan Gauld


"Al Stern"  wrote

Thanks for the advice.  I think I have the dictionary function set 
up right

now although I'm still not clear why it is better than the list.

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 
0}


Consider where you want to update the points for "health"

Using two lists you need to loop over the keys list to find the index
of "health" then access the values list to set the points. Something
like this:

for x in range(len(keys)):
   if keys[x] == "health":
   values[x] = newValue

With a dictionary you just need to do

attributes["health"] = newValue

That's a lot less typing and will be faster performance too.
I'd also say its a lot easier to see whats happening - its more 
readable.


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-06 Thread Al Stern
Thanks for the advice.  I think I have the dictionary function set up right
now although I'm still not clear why it is better than the list.

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}

I think my next task is to set up a while function based on when
available_points drops below 0.  A little lost on how to do it though.

-Original Message-
From: tutor-bounces+alans=risingrealty@python.org
[mailto:tutor-bounces+alans=risingrealty@python.org] On Behalf Of Robert
Sjöblom
Sent: Monday, December 06, 2010 8:04 AM
To: tutor@python.org
Subject: Re: [Tutor] role playing game - help needed

>I am starting with a book called Python Programming for the Absolute
Beginner by Michael Dawson.  The book has been >pretty good >and up to this
point, I have grasped all the concepts it has covered.  At the end of each
chapter, there are a number of challenges you >need to complete before
moving on.  Problem is, I have gotten stumped on one in Chapter 5: Lists and
Dictionaries.
[snip]
> attributes = ["strength", "health", "wisdom", "dexterity"]
> points = [0,0,0,0]
> MAX_POINTS = 30
> available_points = MAX_POINTS - sum(points)

Before anyone comments that you can write a function for the points
system, which was helpful to me when I asked a question regarding that
very chapter: The book doesn't deal with functions until Chapter 6.

As for your problem, Alan; I believe Alan already answered it -- you
have two different lists, attributes and points, but a dictionary
would be easier to handle. Not to say that it couldn't be done the way
you're doing it though. A dictionary is built with key:value pairs.
Then it's just about figuring out a way to change the value associated
with each key when the attribute changes. I don't want to spoil the
challenge of working it out yourself, but when I asked I was told to
check out how values() and sum() worked.

best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-06 Thread Robert Sjöblom
>I am starting with a book called Python Programming for the Absolute Beginner 
>by Michael Dawson.  The book has been >pretty good >and up to this point, I 
>have grasped all the concepts it has covered.  At the end of each chapter, 
>there are a number of challenges you >need to complete before moving on.  
>Problem is, I have gotten stumped on one in Chapter 5: Lists and Dictionaries.
[snip]
> attributes = ["strength", "health", "wisdom", "dexterity"]
> points = [0,0,0,0]
> MAX_POINTS = 30
> available_points = MAX_POINTS - sum(points)

Before anyone comments that you can write a function for the points
system, which was helpful to me when I asked a question regarding that
very chapter: The book doesn't deal with functions until Chapter 6.

As for your problem, Alan; I believe Alan already answered it -- you
have two different lists, attributes and points, but a dictionary
would be easier to handle. Not to say that it couldn't be done the way
you're doing it though. A dictionary is built with key:value pairs.
Then it's just about figuring out a way to change the value associated
with each key when the attribute changes. I don't want to spoil the
challenge of working it out yourself, but when I asked I was told to
check out how values() and sum() worked.

best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] role playing game - help needed

2010-12-06 Thread Alan Gauld


"Alan Stern"  wrote


Hi all.  My name is Al Stern.


Hi Al,


Chapter 5: Lists and Dictionaries.


Note Lists AND Dictionaries


I'm not sure exactly how this mailing list works but
was hoping someone here could give me some insight


You are doing just fine.
The only extra info we could find helpful; are the Python version you 
use

and the OS you run.

For now, I'll assume Python v3 and Windows...

I think I did ok setting up the variables but haven't figured out 
where to go from there.

...

Here is what I have (along with my latest error message).


I don;t see any error messages?
BTW. Please post complete error messages not just summaries.

Notice the topic. You have Lists but I see no dictionaries.
Think about how a dictionary works and how it could be useful here.


attributes = ["strength", "health", "wisdom", "dexterity"]
points = [0,0,0,0]


You ave a list of attributes and a separate list of points.
A dictionary holds a set of keys and associated values.
Can you see a connection?

MAX_POINTS = 30
available_points = MAX_POINTS - sum(points)

print ("You have", available_points, "points available to use.")

for x in range(len(attributes)):
 print ("\t",attributes[x], points[x])

for x in range(len(attributes)):
   point_choice = input("\n\nHow many points do you want to assign to 
" +  attributes[x]  + "?: ")



A start would be to convert the result to an integer and then assign 
that

to points[x]... Then modify available_points as needed.

However using a dictionary will simplify things considerably.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] role playing game - help needed

2010-12-05 Thread Alan Stern
Hi all.  My name is Al Stern.  I am an absolute beginner to programming and 
based on what I'd read, decided to try Python as my 1st language.  I am 
starting with a book called Python Programming for the Absolute Beginner by 
Michael Dawson.  The book has been pretty good and up to this point, I have 
grasped all the concepts it has covered.  At the end of each chapter, there are 
a number of challenges you need to complete before moving on.  Problem is, I 
have gotten stumped on one in Chapter 5: Lists and Dictionaries.

I'm not sure exactly how this mailing list works but was hoping someone here 
could give me some insight as to how to proceed.  Apologies if I am not posting 
the following in the correct format.  I just copied and pasted.)  Feel free to 
point me in the right direction if there are instructions as to how to do it.

Here is the challenge: Write a Character Creator program for a role-playing 
game. The player should be given a pool of 30 points to spend on four 
attributes: Strength, Health, Wisdom, and Dexterity. The >player should be able 
to spend points from the pool on any attribute and should also be able to take 
points from an attribute and put them back into the pool.

I think I did ok setting up the variables but haven't figured out where to go 
from there.

Here is what I have (along with my latest error message).  Thanks in advance.

# character creator / role playing game
# have 30 total points to work with

# set variables

attributes = ["strength", "health", "wisdom", "dexterity"]
points = [0,0,0,0]
MAX_POINTS = 30
available_points = MAX_POINTS - sum(points)

print("""
Our hero will need strength, health, wisdom and dexterity to survive.
You will have a limited amount of points to 'spend' on these attributes.
Use them wisely.  His life depends on it.
"""
)

# point allocation

print ("You have", available_points, "points available to use.")

for x in range(len(attributes)):
  print ("\t",attributes[x], points[x])

for x in range(len(attributes)):
point_choice = input("\n\nHow many points do you want to assign to " +  
attributes[x]  + "?: ")


__
Alan Stern

Rising Realty
1820 W. Webster Ave #307
Chicago, IL 60614

(W)773-395-
(F)773-395-9553
(C)773-502-2556

www.risingrealty.com
Statement of Confidentiality
The contents of this e-mail message and its attachments are intended solely for 
the addressee(s) hereof. In addition, this e-mail transmission may be 
confidential and it may be subject to privilege protecting communications 
between attorneys or solicitors and their clients. If you are not the named 
addressee, or if this message has been addressed to you in error, you are 
directed not to read, disclose, reproduce, distribute, disseminate or otherwise 
use this transmission. Delivery of this message to any person other than the 
intended recipient(s) is not intended in any way to waive privilege or 
confidentiality.  If you have received this transmission in error, please alert 
the sender by reply e-mail; we also request that you immediately delete this 
message and its attachments, if any. Rising Realty reserve the right to monitor 
all e-mail communications through their networks.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor