Re: [Tutor] please return flys in ointment

2013-07-07 Thread Dave Angel

On 07/07/2013 02:47 AM, Jim Mooney wrote:

On 6 July 2013 22:52, Dave Angel da...@davea.name wrote:
The

other author does not use hyphens or commas in the words.  He ends each
string with a blank.  And he neglected to handle zero.





He also is buggy beyond a nonillion-1.


I found yet another implementation that does work up to at least a 
decillion, and it agrees with yours throughout (actually, the testing 
was done with the same million random probes as what I posted earlier.)


However, he also omits the commas and the hyphens.

An interesting site is:

http://rosettacode.org/wiki/Names_to_numbers

which has a bunch of different languages (and programmers) implementing 
the same concept.  Note that the spec didn't say how the words should be 
laid out, and there are many variations in result between the various 
implementations.  These include not only the hyphens, commas, but also 
the use of the word 'and' between some parts of the numbers.





--
DaveA

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


Re: [Tutor] please return flys in ointment

2013-07-07 Thread Alan Gauld

On 07/07/13 08:44, Jim Mooney wrote:


thought about it, but it seemed to me that when most people are
verbalizing big numbers, they tend not to use 'and.'


True in the USA but not the UK (and derivatives?).
Here most folks seem to put the 'and' in.

eg: three thousand, four hundred and fifty six...

Incidentally, if you get any Indian users they'll be looking
for support for 'laks' - 100,000's :-)

HTH

--
Alan G
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] Combat Error

2013-07-07 Thread Jack Little
When the player of my game fire his/her cannon, it is supposed to get rid of 
some of the enemy's health. It does not. I have no clue what the error is, so I 
need help. Here is the Python Shell output:

fire cannon 1
Fired!
Enemy health= 75
They fired at you!
Your health is now 55
fire cannon 2
Fired!
Enemy health= 75
They fired at you!
Your health is now 55
fire cannon 1
Fired!
Enemy health= 75
They fired at you!
Your health is now 55





Here is the code:

def lvl4combat():
    print The barracks are constructed of wood and cobblestone.
    print A large, single cannon sits on the top, searching the sky for enemy 
airships.
    print The cannon is manned by a single team of three men.
    print The cannon is large and industrial.
    print Remember your training.
    cannonhealth=75
    cannondamage=random.choice([10,17,13])
    currhealth=health
    while cannonhealth  0:
        print They fired at you!
        currhealth-cannonhealth
        print Your health is now,currhealth
        combat=raw_input()
        if combat.lower()==fire cannon 1:
            print Fired!
            cannonhealth-attack
            print Enemy health=,cannonhealth
        elif combat.lower()==fire cannon 2:
            print Fired!
            cannonhealth-attack
            print Enemy health=,cannonhealth
        if currhealth = 0:
            break
            defeat1()
        if cannonhealth = 0:
            break
            victory1()
            if kboost==True:
                karma+25*.25
            elif kboost==False:
                karma+25___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Combat Error

2013-07-07 Thread Dave Angel

On 07/07/2013 06:40 PM, Jack Little wrote:

When the player of my game fire his/her cannon, it is supposed to get rid of 
some of the enemy's health. It does not. I have no clue what the error is, so I 
need help. Here is the Python Shell output:


fire cannon 1

Fired!
Enemy health= 75
They fired at you!
Your health is now 55

fire cannon 2

Fired!
Enemy health= 75
They fired at you!
Your health is now 55

fire cannon 1

Fired!
Enemy health= 75
They fired at you!
Your health is now 55







Here is the code:

def lvl4combat():
 print The barracks are constructed of wood and cobblestone.
 print A large, single cannon sits on the top, searching the sky for enemy 
airships.
 print The cannon is manned by a single team of three men.
 print The cannon is large and industrial.
 print Remember your training.
 cannonhealth=75
 cannondamage=random.choice([10,17,13])
 currhealth=health
 while cannonhealth  0:
 print They fired at you!
 currhealth-cannonhealth
 print Your health is now,currhealth
 combat=raw_input()
 if combat.lower()==fire cannon 1:
 print Fired!
 cannonhealth-attack


This expression has no useful effect.  You probably wanted

  cannonhealth -= attack


 print Enemy health=,cannonhealth
 elif combat.lower()==fire cannon 2:
 print Fired!
 cannonhealth-attack


ditto


 print Enemy health=,cannonhealth
 if currhealth = 0:
 break
 defeat1()
 if cannonhealth = 0:
 break
 victory1()
 if kboost==True:
 karma+25*.25


ditto


 elif kboost==False:
 karma+25


ditto


You also have code following break statements that will never execute. 
In particular, you'll never call defeat1() or victory1()




--
DaveA

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


Re: [Tutor] Combat Error

2013-07-07 Thread Steven D'Aprano

On 08/07/13 08:40, Jack Little wrote:



def lvl4combat():
 print The barracks are constructed of wood and cobblestone.
 print A large, single cannon sits on the top, searching the sky for enemy 
airships.
 print The cannon is manned by a single team of three men.
 print The cannon is large and industrial.
 print Remember your training.
 cannonhealth=75


Here you start with cannonhealth set to 75. But you never lower the score, so 
it never changes and the loop doesn't end.



 cannondamage=random.choice([10,17,13])
 currhealth=health
 while cannonhealth  0:
 print They fired at you!
 currhealth-cannonhealth


Here you calculate the number (currhealth - cannonhealth), which is the 
difference between your health and the cannon's health, but do nothing with the 
result. Which is probably a good thing, since the calculation doesn't mean 
anything.

Perhaps you meant this?

currhealth = currenthealth - cannondamage

or even this, which is another way of doing the same calculation:

currhealth -= cannondamage




 print Your health is now,currhealth
 combat=raw_input()
 if combat.lower()==fire cannon 1:
 print Fired!
 cannonhealth-attack


Here you calculate the number (cannonhealth - attack), which is the difference 
between the cannon's health and the damage done, but do nothing with the result.

As I suggested the last time you made this same error, you might find it easier 
to see the problem if you put spaces around operators, so that they are a 
little easier to notice and read:

cannonhealth - attack
cannonhealth-attack


Like the above, you probably want:

cannonhealth = cannonhealth - attack


And you make a similar mistake in at least three other places. I will leave you 
to find them.


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


Re: [Tutor] Combat Error

2013-07-07 Thread Alan Gauld

On 07/07/13 23:40, Jack Little wrote:

When the player of my game fire his/her cannon, it is supposed to get
rid of some of the enemy's health. It does not. I have no clue what the
error is,


Its not entirely clear to me who is 'you' and who is 'the enemy'
Why does the enemy firing a cannon at me affect the enemy's
health? I see how it might affect my health but not the enemies
(it might affect their ammunition supplies but that's another story!)



 while cannonhealth  0:

snip...


 if combat.lower()==fire cannon 1:
 print Fired!
 cannonhealth-attack


I assume these lines are supposed to modify cannonhealth?
In fact they do nothing since you don't assign the result.
You probably want

  cannonhealth -= attack



 print Enemy health=,cannonhealth
 elif combat.lower()==fire cannon 2:
 print Fired!
 cannonhealth-attack
 print Enemy health=,cannonhealth
 if currhealth = 0:
 break
 defeat1()


You do realize that code after a break will never be executed? The break 
immediately leaves the loop, it does not execute any further statements.




 if cannonhealth = 0:
 break


same here. All following code is ignored.


 victory1()
 if kboost==True:
 karma+25*.25


I doubt this does what you think it does. You should really get used to 
using the  prompt to try out things...


 10+25*.25
16.25
 (10+25)*.25
8.75
 10+(25*.25)
16.25


But since you don't assign the result to anything it's pretty harmless 
in that it has no impact on the code whatsoever except to waste some time.



 elif kboost==False:
 karma+25


Same here. No assignment means no change.

To be honest, it kind of feels like you don't have any design for
this thing. You are just making it up as you go along. While evolution
is an amazing mechanism for random change it has the downside of
taking a very long time to produce useful results. If you plan to
progress quickly, design wins every time! Paper and pencils are
still effective tools.

HTH
--
Alan G
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