[Tutor] Repeat Until Dead

2013-06-26 Thread Jack Little
In a combat system, how would I have a certain raw_input repeat until the enemy 
is dead?



Thanks a ton,
Jack___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Repeat Until Dead

2013-06-26 Thread Marc Tompkins
On Wed, Jun 26, 2013 at 11:23 AM, Jack Little wrote:

> In a combat system, how would I have a certain raw_input repeat until the
> enemy is dead?
>
Sounds like a classic case for a "while" loop.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Rbtg da sneak

2013-06-26 Thread Justin Dahl
Invc.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Nf

2013-06-26 Thread Justin Dahl
Bl u
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Hnoddlgfob

2013-06-26 Thread Justin Dahl
Ce xnocr u
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Repeat Until Dead

2013-06-26 Thread Danilo Chilene
Hello,

Try something like this:

coin = raw_input('Insert coins:\n')

while(coin > 0):
coin = int(coin)-1
print 'You have {0} coin(s)'.format(coin)

$ python teste.py
Insert coins:
2
You have 1 coin(s)
You have 0 coin(s)



On Wed, Jun 26, 2013 at 3:30 PM, Chris “Kwpolska” Warrick <
kwpol...@gmail.com> wrote:

> On Wed, Jun 26, 2013 at 8:23 PM, Jack Little 
> wrote:
> > In a combat system, how would I have a certain raw_input repeat until the
> > enemy is dead?
> >
> >
> > Thanks a ton,
> > Jack
>
> Something like this:
>
> while enemyalive:
> raw_input('Action? ')
>
> --
> Kwpolska  | GPG KEY: 5EAAEA16
> stop html mail| always bottom-post
> http://asciiribbon.org| http://caliburn.nl/topposting.html
> ___
> 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] Repeat Until Dead

2013-06-26 Thread Alan Gauld

On 26/06/13 23:07, Danilo Chilene wrote:

Hello,

Try something like this:

coin = raw_input('Insert coins:\n')

while(coin > 0):
 coin = int(coin)-1
 print 'You have {0} coin(s)'.format(coin)


Note you did not convert the original raw_input value to an int.
Also you keep on converting coins to int inside the loop even
though it already is one after the first iteration. However...

This only loops for as many times as coin is set at the beginning.
The OP needs the raw_input inside the loop so it would need to look
like this:

coin = int( raw_input('Insert coins:\n') )
while(coin > 0):
 print 'You have {0} coin(s)'.format(coin)
 coin = int( raw_input('Insert coins:\n') )

What we don't know, because the OP didn't tell us, is how
he detects "death"... I hope he can adapt...

--
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] using python for parsing

2013-06-26 Thread Makarand Datar
Hi,

I know practically nothing about python. I know how to install it and all
that kind of stuff. I want to use python for parsing a text file. The task
is to read in a text file, and write out another text file that is written
in some particular way using the data from the file that was read in. The
question is how do I go about this? What part of python documentation, or a
book I should read etc. I dont want to start reading a python book from the
first page. I just want to do this parsing task and I will learn about
whatever I need to as I encounter it.

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


Re: [Tutor] Question about python for web

2013-06-26 Thread Seshadri Raja
Dear Dat,

Sorry for the late reply.

The path of the python should be #!/usr/bin/python (or) #!/usr/bin/env
python. Forward Slash(/) is missing in your CGI script.

​Enable the ExecCGI for your DocumentRoot

Ref:
http://httpd.apache.org/docs/current/howto/cgi.html​

​

Options +ExecCGI

​

Kindly try and let us know the details.

Kind Regards
:: S. Seshadri Raja ::




On Sun, Jun 23, 2013 at 6:12 PM, Dat Huynh  wrote:

> Dear all,
>
> I have a very simple question about running a simple web application with
> apache on MacOS.
>
> Step 1: Copy the file mod_wsgi.so from the link
>
> http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-macosx106-ap22py26-3.3.so
> into the folder "/usr/libexec/apache2"
>
>
> Step 2: Add the following line:
>
>   LoadModule wsgi_module libexec/apache2/mod_wsgi.so
> into the file "/etc/apache2/httpd.conf"
>
>
> Step 3: Edit a file "test.py" as below and copy the file to the folder
> "/Library/WebServer/Documents".
>
> #!usr/bin/python
> print "Content-type: text/html"
> print
> print ""
> print ""
> print ""
> print "Test Page"
> print ""
>
> When I type the following url "http://localhost/test.py"; on my browser, I
> see exactly the content of the file, NOT the text "Test Page" only.
>
> I think I miss something in the procedure.
> What should I do to make my browser process the received HTML data?
>
> Thank you very much.
>
> Sincerely,
> Dat.
>
> ___
> 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] using python for parsing

2013-06-26 Thread Alan Gauld

On 26/06/13 18:05, Makarand Datar wrote:


I know practically nothing about python. I know how to install it and
all that kind of stuff. I want to use python for parsing a text file.


So far so good. Do you know how to program in any other language?
It will help us direct you to a source if we know your level of prior 
knowledge.



The task is to read in a text file, and write out another text file that
is written in some particular way using the data from the file that was
read in.


Again, so far so good.


The question is how do I go about this? What part of python
documentation, or a book I should read etc. I dont want to start reading
a python book from the first page. I just want to do this parsing task
and I will learn about whatever I need to as I encounter it.


Unless you are already very familiar with another programming
language then that is a very inefficient way to learn.
However if you really have the time to bounce about looking
up random references so you can understand one chapter you
can try the Handling Files topic in my tutorial.
It does however assume you've read the preceding topics

As a matter of interest, if you wanted to play a tune on
guitar would you ask to learn only how to play the specific
notes in that tune?

--
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


Re: [Tutor] Install BTrees

2013-06-26 Thread Alan Gauld

On 26/06/13 10:56, Wanbo Li wrote:

Dear all,

I am trying to install BTrees package on Mac OS X 10.7.5. And my python version 
is 2.7.3

So I used 'easy_install ZODB' and 'easy_install BTrees' to install the packages.


This list is for people learning the Python language and its standard 
library. Since this appears to be Zope related you should probably

try a Zope forum/list.

However, you may be lucky and somebody here might actually know
how to help you...

--
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] While problem

2013-06-26 Thread Jack Little
I have a small problem with the while function.It prints an odd variable that 
has nothing to do with the function. It prints "Squad One!". Here is my code 
for the 3 def's that have something to do with the while function.



def tcombat():
    c1am=10
    c2am=10
    enam="Qasi"
    ehealth=15
    edam=random.choice([5,6,7,8,9])
    thealth=20
    tdam=random.choice([6,7,8,9,10])
    enemyalive=True
    while enemyalive==True:   
        t2=raw_input(">>")
        if t2.lower=="FIRE CANNON 1":
            c1am-=c1am-1
            ehealth-tdam
            print "Cannon Fired!"
            print "Enemy Health=", ehealth
            
        elif t2.lower=="FIRE CANNON 2":
            c2am=c2am-1
            ehealth-tdam
            print "Cannon Fired!"
            print "Enemy Health=", ehealth
    print "Good Job!"
    print "You beat the training dummy."
    print "Nothing like real combat"
    print "But screw you, here you go!"
    print "(Into real combat)"
    lvl3()

def lvl2_2():
    print "Squad Nine"
    print "This team looks veryumm..Dumb."
    print "There is one guy sitting on a stool"
    print "he has a star sticker on his chest."
    print "The other guy is vomiting on his"
    print "pants."
    print "BEGIN TRAINING"
    print "TRAINING: When you are roaming around the skies, you type 'Engage 
[Ship Name]'"
    print "TRAINING: While in combat, type 'Fire [Cannon Number (not spelt)]' 
to fire a cannon at a ship"
    print "All entries must be in lower caps!"
    print "TRAINING: There may be consequences for firing upon certain ships."
    print "--BEGIN TRAINING--"
    print "There is a ship near yours, the Qasi. It is flying"
    print "the enemy flag."
    print "There are 2 cannons on your ship."
    c1am=10
    c2am=10
    enam="Qasi"
    ehealth=15
    edam=random.choice([5,6,7,8,9])
    thealth=20
    tdam=random.choice([6,7,8,9,10])
    enemyalive=True
    if ehealth==0:
        enemyalive=False
    t1=raw_input(">>")
    if t1.lower=="engage qasi":
        print enam ,"Engaged in Combat"
        tcombat()
   
    

def lvl2_1():
    print "Squad One"
    print "This team looks much more able than Squad Nine."
    print "TYRONE:Hi! I'm Tyrone, he's James, she's Ashley, and that guy over 
there,"
    print "he's Bob."
    print "BEGIN TRAINING"
    print "TRAINING: When you are roaming around the skies, you type 'Engage 
[Ship Name]'"
    print "TRAINING: While in combat, type 'Fire [Cannon Number (not spelt)]' 
to fire a cannon at a ship"
    print "TRAINING: There may be consequences for firing upon certain ships."
    print "--BEGIN TRAINING--"
    print "There is a ship near yours, the Qasi. It is flying"
    print "the enemy flag."
    print "There are 2 cannons on your ship."
    c1am=10
    c2am=10
    enam="Qasi"
    ehealth=15
    edam=random.choice([5,6,7,8,9])
    thealth=20
    tdam=random.choice([6,7,8,9,10])
    enemyalive=True
    if ehealth==0:
        enemyalive=False
    t1=raw_input(">>")
    if t1.lower=="ENGAGE QASI":
        print "Engaged in Combat"
        tcombat()




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


Re: [Tutor] using python for parsing

2013-06-26 Thread Steven D'Aprano

On 27/06/13 03:05, Makarand Datar wrote:

Hi,

I know practically nothing about python. I know how to install it and all
that kind of stuff. I want to use python for parsing a text file. The task
is to read in a text file, and write out another text file that is written
in some particular way using the data from the file that was read in. The
question is how do I go about this? What part of python documentation, or a
book I should read etc. I dont want to start reading a python book from the
first page. I just want to do this parsing task and I will learn about
whatever I need to as I encounter it.



That depends on what you mean by "written in some particular way". It also 
depends on what version of Python, and what operating system. (I assume Windows, since 
Python is nearly always pre-installed on Linux.)

The simplest, most basic way is to do this is something like this:

filename = "C:/path/to/some/file.txt"
f = open(filename, 'r')
for line in f:
print(line)

f.close()



In more recent versions, this is perhaps better written as:

filename = "C:/path/to/some/file.txt"
with open(filename, 'r') as f:
for line in f:
print(line)



Don't forget that indentation is significant.

Instead of print(line), a more realistic example would parse the line in some way, and 
that depends on the "particular way" you mention above. For example, given some 
line, I might split it into words, then print the first word, the second word, and the 
last letter of the third word:


words = line.split()
print(words[0], words[1], words[2][-1])



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


Re: [Tutor] While problem

2013-06-26 Thread Dave Angel

On 06/26/2013 08:32 PM, Jack Little wrote:

I have a small problem with the while function.It prints an odd variable


What variable is that?


that has nothing to do with the function. It prints "Squad One!". Here is my 
code for the 3 def's that have something to do with the while function.




It's not at all clear what you want from us.  There aren't any while 
functions (since that would be a syntax error), though I do see a while 
statement in the tcombat() function.  Is that the one you're referring to?


I also see calls to functions you didn't provide, and since the logic 
makes no sense to me, it's not obvious whether they matter or not. 
Nothing here calls  lvl2_1(), so should we assume it's dead code?  For 
that matter, neither of the references to tcombat() will ever actually 
call it, so it's dead too?


Are you just looking for someone to correct your obvious mistakes?  Like 
the if statement and the elif statement that will never fire, because 
you forgot parentheses on the t2.lower method call ?  (And once you fix 
that, they'll still never fire, since you're then comparing uppercase to 
lowercase, and obviously they're different).


Because of that, the while statement will never terminate, just 
repeatedly asking for raw_input (with a prompt of ">>") and getting 
stuck till the user creates an exception, like Ctrl-C.




def tcombat():
 c1am=10
 c2am=10
 enam="Qasi"
 ehealth=15
 edam=random.choice([5,6,7,8,9])
 thealth=20
 tdam=random.choice([6,7,8,9,10])
 enemyalive=True
 while enemyalive==True:
 t2=raw_input(">>")
 if t2.lower=="FIRE CANNON 1":
 c1am-=c1am-1
 ehealth-tdam
 print "Cannon Fired!"
 print "Enemy Health=", ehealth

 elif t2.lower=="FIRE CANNON 2":
 c2am=c2am-1
 ehealth-tdam
 print "Cannon Fired!"
 print "Enemy Health=", ehealth
 print "Good Job!"
 print "You beat the training dummy."
 print "Nothing like real combat"
 print "But screw you, here you go!"
 print "(Into real combat)"
 lvl3()


Does lvl3() look anything like  lvl2_2() below?  If so, you're looking 
for trouble, recursively calling between tcombat() and the various other 
functions.  Eventually, the stack fills up.  A function call is not a 
goto statement.




def lvl2_2():
 print "Squad Nine"
 print "This team looks veryumm..Dumb."
 print "There is one guy sitting on a stool"
 print "he has a star sticker on his chest."
 print "The other guy is vomiting on his"
 print "pants."
 print "BEGIN TRAINING"
 print "TRAINING: When you are roaming around the skies, you type 'Engage [Ship 
Name]'"
 print "TRAINING: While in combat, type 'Fire [Cannon Number (not spelt)]' to 
fire a cannon at a ship"
 print "All entries must be in lower caps!"
 print "TRAINING: There may be consequences for firing upon certain ships."
 print "--BEGIN TRAINING--"
 print "There is a ship near yours, the Qasi. It is flying"
 print "the enemy flag."
 print "There are 2 cannons on your ship."
 c1am=10
 c2am=10
 enam="Qasi"
 ehealth=15
 edam=random.choice([5,6,7,8,9])
 thealth=20
 tdam=random.choice([6,7,8,9,10])


You never use the values of edam, thealth, and tdam.  So why calculate them?


 enemyalive=True
 if ehealth==0:
 enemyalive=False


This statement and the similar one above did nothing useful. You never 
check the value of enemyalive in this function.



 t1=raw_input(">>")
 if t1.lower=="engage qasi":
 print enam ,"Engaged in Combat"
 tcombat()



def lvl2_1():
 print "Squad One"
 print "This team looks much more able than Squad Nine."
 print "TYRONE:Hi! I'm Tyrone, he's James, she's Ashley, and that guy over 
there,"
 print "he's Bob."
 print "BEGIN TRAINING"
 print "TRAINING: When you are roaming around the skies, you type 'Engage [Ship 
Name]'"
 print "TRAINING: While in combat, type 'Fire [Cannon Number (not spelt)]' to 
fire a cannon at a ship"
 print "TRAINING: There may be consequences for firing upon certain ships."
 print "--BEGIN TRAINING--"
 print "There is a ship near yours, the Qasi. It is flying"
 print "the enemy flag."
 print "There are 2 cannons on your ship."
 c1am=10
 c2am=10
 enam="Qasi"


You never use enam.  It looks useful, so how did you expect to be using it?


 ehealth=15
 edam=random.choice([5,6,7,8,9])
 thealth=20
 tdam=random.choice([6,7,8,9,10])
 enemyalive=True
 if ehealth==0:
 enemyalive=False


This local variable is never referenced.  So why set it?  Of course that 
doesn't really matter, since ehealth is not going to be zero;  it's 
initialized right above to 15.



 t1=raw_input(">>")
 if t1.lower=="ENGAGE QASI":


This will never be equal, so the following never happens.


 print "E

Re: [Tutor] While problem

2013-06-26 Thread Steven D'Aprano

On 27/06/13 10:32, Jack Little wrote:

I have a small problem with the while function.It prints an odd variable that has nothing 
to do with the function. It prints "Squad One!". Here is my code for the 3 
def's that have something to do with the while function.


But you don't actually show us the while loop that prints "Squad One!". That's 
rather less than useful. How do you expect us to fix the broken code without seeing it?

"Hello Mr Mechanic, I have a car that is making a strange noise when I turn left. 
Rather than bring that car in for you to look at, I thought I'd bring in the three cars 
that are parked next to it, just in case the problem is with them..."

:-)



Some unrelated comments below:



def tcombat():
 c1am=10
 c2am=10
 enam="Qasi"
 ehealth=15
 edam=random.choice([5,6,7,8,9])


"edam"? Like the cheese?



 thealth=20
 tdam=random.choice([6,7,8,9,10])
 enemyalive=True
 while enemyalive==True:


You don't need to say "while enemyalive == True", since enemyalive is already a true or 
false value. Just say "while enemyalive:".



 t2=raw_input(">>")
 if t2.lower=="FIRE CANNON 1":


This cannot every succeed, since you are comparing the *method* (like a function) 
t2.lower with the *string* "FIRE CANNON 1". You need to actually *call* the 
method, to get a result:

if t2.lower() == "FIRE CANNON 1":

which of course also can never succeed, since you're comparing a lowercase 
string with an UPPERCASE string. You need one of these instead:

if t2.lower() == "fire cannon 1":

if t2.upper() == "FIRE CANNON 1":



 c1am-=c1am-1


If you think about this mathematically, you will see that this cannot fail to set c1am to 
1. If that's what you intended, just write "c1am = 1". Or if you meant to 
subtract 1 from c1am, then you can write either of these:

c1am = c1am - 1

c1am -= 1

My suggestion is that you are less likely to make these sorts of errors if you 
put spaces around equal signs and other operators. Spaces make things easier to 
read, or another way to put it, notusingspacesmakesthingsmuchhardertoread.


(By the way, I hope these variable names mean something to you, because most of them mean 
absolutely nothing to me. "c1am"? WTH does that stand for?)



 ehealth-tdam


This line is useless, since it just calculates the value ehealth - tdam, then 
throws the result away unused. Perhaps you meant this?

ehealth -= tdam



 print "Cannon Fired!"
 print "Enemy Health=", ehealth

 elif t2.lower=="FIRE CANNON 2":


The same flaw applies here as above.



 c2am=c2am-1
 ehealth-tdam


Likewise.



 print "Cannon Fired!"
 print "Enemy Health=", ehealth
 print "Good Job!"
 print "You beat the training dummy."
 print "Nothing like real combat"
 print "But screw you, here you go!"
 print "(Into real combat)"
 lvl3()

def lvl2_2():
 print "Squad Nine"
 print "This team looks veryumm..Dumb."
 print "There is one guy sitting on a stool"
 print "he has a star sticker on his chest."
 print "The other guy is vomiting on his"
 print "pants."
 print "BEGIN TRAINING"
 print "TRAINING: When you are roaming around the skies, you type 'Engage [Ship 
Name]'"
 print "TRAINING: While in combat, type 'Fire [Cannon Number (not spelt)]' to 
fire a cannon at a ship"
 print "All entries must be in lower caps!"


"Lower caps"? Do you mean lower case? ALL CAPS?



 print "TRAINING: There may be consequences for firing upon certain ships."


Oh good. Consequences. Are they good consequences or bad consequences?



By the way, your code contains an awful lot of duplicated code. You should pull 
out the duplicated code and put it into functions, then pass an appropriate 
variable to the function. A simplified example follows.

Instead of this duplicated code:

def squad_one():
print "This is squad one."
print "You're training"
print "Do this"
print "Do that"
print "Do something else"

def squad_two():
print "This is squad two."
print "You're training"
print "Do this"
print "Do that"
print "Do something else"


if squad == "squad one":
squad_one()
else:
squad_two()



you can instead do this:


def squad(name):
print "This is Squad %s." % name
print "You're training"
print "Do this"
print "Do that"
print "Do something else"

if squad == "squad one":
squad("one")
else:
squad("two")



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


Re: [Tutor] Typing 'h', 'e', 'l', 'p', 'Enter' in a window

2013-06-26 Thread Marc Tompkins
On Wed, Jun 26, 2013 at 1:45 PM, kdarroud  wrote:

> In our Windows machine, we have several windows open.
> Using Python, how can I type 'h', 'e', 'l', 'p', 'Enter' in a specific
> window that is open?
>

In general, Python out-of-the-box doesn't know about OS-specific things
like interacting with other windows; you need to interact with the
operating system to do that.  In the case of Windows, there's a module
called pywin - http://sourceforge.net/projects/pywin32/ - that provides a
Python-accessible wrapper around the Windows API.

Basically, you need to find the Windows API call(s) you need in order to
achieve your goal (definitely not a Python question; some folks on this
list might be able to help you, but there are better resources for Windows
programmers), and then call them via pywin.  The pywin documentation is
very, very minimal - _all_ that pywin does is provide a Python binding for
Windows API calls.

If you have questions about invoking pywin after you've downloaded and
installed it, or general Python questions, this list is the place.  For
everything else... not so much.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor