> I understand the format of while loops, but is it possible to use the
> random.randrange function in them?
>
> My goal, create a program that flips a coin 100 times, at the end it
> says the number of times it flipped heads and flipped tails.
I am also trying to learn python and came across
I am confused. It looks to me as if the while loop will never work,
because it stays inside while <100 and further down in the loop, if
it is < 100, it should go out of the loop. How can it stay running
while <100 and yet go out if < 100?
Johan
Nick Eberle wrote:
print
"This is a
On Tue, 25 Oct 2005, Nick Eberle wrote:
> My goal, create a program that flips a coin 100 times, at the end it
> says the number of times it flipped heads and flipped tails.
Hi Nick,
Do you might if we simplify the problem slightly? Say that you're only
flipping the coin two times. Can you
> > My goal, create a program that flips a coin 100 times, at the end it
> > says the number of times it flipped heads and flipped tails.
>
> Do you might if we simplify the problem slightly? Say that you're only
> flipping the coin two times. Can you write code to say how many times
> it flip
Hello,
I'm not so sure about your problem, but
probably this code can help
sumHead, sumTail = 0,0
listHeadTime = [] listTailTime = [] for i in range(100): time_start = time.clock() coin = random.randint(0,1) # 0 head, 1 tail time_stop = time.clock()
As Danny says, try breaking the problem into chunks and solving
each bit separately. I'll provide a few comments on your code in
the meantime but try the "evolving soluition" approach too.
#assigning variables to track the amount of times heads or tails comes up
heads=0
tails=1
AG> Why not make b
Chris Hallman wrote:
> I was finally able to get my script to not show duplicate PINGs. I also
> realized that my script was not PINGing all the hosts in the input file.
Congratulations on getting it to work! See below for a few notes.
> Here is my latest version:
>
>
> import os, re, string
This may not be up to the standard of the more experienced programmer
but here is my effort. An added bit is the ability to go on using the
code until you are fed up.
#To check the computers odds and evens
import random
anothergo = "y"
while(anothergo != "n"):
oddsevens = random.randrange(2
I have script that calls a system command that I want to run for 5 minutes.
"""
import os
cmd = 'tcpdump -n -i eth0'
os.system(cmd)
"""
I can start a timer after the cmd is issued, but I don't know how to
send a control signal to stop the command after I issued it. This is
normally from the shel
Johan Geldenhuys wrote:
> I have script that calls a system command that I want to run for 5 minutes.
> """
> import os
> cmd = 'tcpdump -n -i eth0'
> os.system(cmd)
> """
>
> I can start a timer after the cmd is issued, but I don't know how to
> send a control signal to stop the command after I
So, for a newbie like me I might struggle with this one :-(
I saw that the thread in comp.lang.python talks about a deamon flag for
a thread. This sounds like a idea that could work. I don't know how to
use that, but will use the example given there.
Thanks.
Kent Johnson wrote:
Johan Ge
Hi all,
I've a question, essentially about the import statement. Suppose I have
two python files, a.py and b.py:
a.py
flag = True
def getFlag():
return flag
b.py
from a import *
now, in the interpreter:
>>> import b
>>> b.flag
True
>>> b.flag=False
>>> b.flag
False
>>> b.getFlag
Dear python experts,
I am a novice python learner and aspiring to become
decent python programmer. I am reading 'Learning
Python' by Mark Lutz et al. and it is one of the good
books that I find in addition to Alan Gauld's book
'Learn to Program Using Python'.
While reading these books step-by
Thank you for posting your code. That really helps us see where you are
and therefore how to help.
I encourage you to "desk check" your code: pretend you are the
computer: write down the values of variables and expressions as things
change. Evaluate each statement to see what it does.
Example:
he
Ahh makes much more sense, thanks for all the help!
I'll go back and rework it, keeping in mind trying to solve each piece
separately.
Thanks again all.
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 26, 2005 1:53 AM
To: Nick Eberle; bob; tutor@p
Yes I am going through the Michael Dawson book. Also, I am working from
the Alan Gauld book to reinforce my attempts at learning python.
Norman
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> I've a question, essentially about the import statement. Suppose I have
> two python files, a.py and b.py:
OK, I'll have a go although I'm only 90% sure I've got it right...
> a.py
>
> flag = True
>
> def getFlag():
>return flag
>
> b.py
>
> from a import *
This imports the nam
i am trying to write a class to log into myspace. either i am doing something wrong, or... myspace is requiring that i accept a cookie, or create a session? however i am new to urllib and urllib2.
heres my code:
correctly formatted code is at: http://www.jeah.net/~marla/myspace.py
#!/bin/env p
> While reading these books step-by-step and progressing
> ahead, I feel that some of the terms are highly
> volatile. In simple terms, while reading about lambda
> functions after reading a lot of stuff before, I am
> unable to clearly define what is an expression and
> what is a statement.
Go
Hi,
os.system will return the errorval of the application. You need to
1) get the pid of the child process
2) kill it using os.kill(os.SIGTERM)
3) reap the killed process
This is all in unix/linux, of course.
what I do (untested, please check order of args and correct usage of exec):
pid = os.
Ed Hotchkiss wrote:
> i am trying to write a class to log into myspace. either i am doing
> something wrong, or... myspace is requiring that i accept a cookie, or
> create a session? however i am new to urllib and urllib2.
It's very likely that myspace is returning a cookie from the login, this
This doesn't seem to have been answered...
"Shi Mu" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I can not understand the use of "cell in row" for two times in the code:
>
> # convert the matrix to a 1D list
> matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]]
> items = [cell for ro
>My son is learning something about using a spreadsheet - extremely
>useful and I support it 100%. That he thinks what he is learning is
>Excel is absolutely unforgivable, in terms of my understanding of
>ethical norms that once prevailed in an institute of higher education.
>
I guess it depends
I am having a problem with Tkinter. The goal is a program that will copy
images from one folder to another then delete them from the source dir
after it is verified that they made it to the target dir. I have the
base functionality figured out (comments on that are welcome of course).
Now I wan
Hello all,
I'm new to python but so far I have to say its a really good language
I've been having some trouble with File IO can anyone help? I've got the
basics but my problem is that I have many files (one for each year of the
last 100 years or so) that look like this:
MONTH RAIN AVTE
Rob Dowell wrote:
> I am having a problem with Tkinter. The goal is a program that will copy
> images from one folder to another then delete them from the source dir
> after it is verified that they made it to the target dir. I have the
> base functionality figured out (comments on that are welc
Hey there,
i am writing some (for me) pretty complicated stuff for work that
really needs to work.
i have looked at exception handling in the Learning Python book.
and i am using some try / except statements.
the problem is, that even though my script does not crash, i don
I'm back to my IRC client. I accidentally found the thread module in the
Python 2.3 documentation while looking at the time module.
What I can't get ideas or hints from the documentation is:
What will i do to receive and send at the same time via console?
or:
Should I forget the i
Yes,
You can catch an error object along with the exception, as in:
try:
fileo = open("nofile")
except IOError, e:
print "Alas...", e
As you see, the error object has a string representation equal wo what
normally the python interpreter prints...
>>>
Alas... [Errno 2] No such file o
Thanks Hugo,
Now that i know where to look
appreciate your help.
-sk
On Wed, 2005-10-26 at 21:27 -0600, Hugo González Monteverde wrote:
> Yes,
>
> You can catch an error object along with the exception, as in:
>
> try:
> fileo = open("nofile")
> except IOError, e:
> print "Alas...
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
os - Slackware
py - 2.4.1
I'm trying to grab the value 10 in
Visibility: 10 mile(s):0
but sometimes the value looks like
Visibility: 1/2 mile(s):0
My not working regex looks like
re.compile(': \d+|: \d/\d')
If I'm understanding right, this shou
> i am writing some (for me) pretty complicated stuff for work that
> really needs to work.
> i have looked at exception handling...
> and i am using some try / except statements.
> the problem is, that even though my script does not crash, i dont know
> the exact error.
>
Yeah, cool. i am just starting this part.
i am glad i started with python.
thanks for the help
sk
On Wed, 2005-10-26 at 21:32 -0700, w chun wrote:
> > i am writing some (for me) pretty complicated stuff for work that
> > really needs to work.
> > i have looked at exception handlin
33 matches
Mail list logo