Re: [Tutor] please help me with after method

2016-11-17 Thread Alan Gauld via Tutor
Always use REply-All or Reply-List to the tutor list.

On 17/11/16 18:34, Freedom Peacemaker wrote:
> Thank you Alan for answer but i still cant make it. I have improved my
> program but it still uses root.update() and now my app looks
> professional :) It is my first program. I am self learning Python
> since july this year but still i need a lot of knowledge. Could you
> help me improve my app with root.after?

OK, I'll try.

> And there is problem - when im closing app with X button after using
> app it shows two windows. One with messagebox i wrote, and second
> blank new tk window. I dont know where im doing mistake, or it is
> caused by root.update maybe? Maybe with using root.after problem will
> be no more.

Maybe, but I'll need to look at the code more closely.
There are a couple of things that could cause this
Having looked, I think you need to bind the window
manager close button to root.quit Take a look at
the wm_ methods in the Tkinter docs.


>
> def displayCountdown():
> lcd = "{:02d}:{:02d}".format(*divmod(t, 60))
> timeString.set(lcd)
> setTime -= 1
> if setTime > 0:
> root.after(1000,displayCountdown)
>

Where is 't' (used in the divmod) defined? Looking below I think
it should use setTime?

Otherwise it looks like it should work. All you need to do is insert
a call to displayCountdown() in your START button event handler.


> There are problems with my app but im so proud that i wrote myself

Its rare that anything is ever perfect but the buzz of getting
something to work more or less as you want it to is always good. :-)

> import sys, time, os
> import tkinter as tk
> from tkinter import *
>

You should probably only ose one of the tkinter imports.
And the first is the preferred method for production code.

> def change_1():
> B1['state'] = tk.DISABLED
> B2['state'] = tk.NORMAL  
>
> def change_2():
> B1['state'] = tk.NORMAL
> B2['state'] = tk.DISABLED
>
> def change_3():
> B1['state'] = tk.DISABLED
> B2['state'] = tk.DISABLED


Add the displayCountdown() definition here

>
> def startCount():
> setTime = setMinutes.get() * 60
> strTime = str(setTime)
> timeSet = ("\""+"shutdown /s /f /t " +strTime+"\"")
> os.system(timeSet)
> change_1()
displayCountdown() # uses the after() method.

This removes the need for all of the code below.

> for t in range(setTime, -1, -1):
> lcd = "{:02d}:{:02d}".format(*divmod(t, 60))
> timeString.set(lcd)
> try:
> root.update()
> except TclError:
> messagebox.showinfo('Info', 'Closing app wont stop timer.')
> return
> time.sleep(1)
> return
>

The rest of your code is unchanged.
But note I haven't tested this! :-)

> def stopCount():
> passwd = "science"
> passwdGet = getPass.get()
> if passwd != passwdGet:

You could make this more secure.
You should probably do some reading about best [practice
for handling passwords. But for now it probably meets your needs.


> messagebox.showinfo('Wrong', 'It wasnt correct password')
> change_3()
> else:
> messagebox.showinfo('Good', 'Shutdown canceled')
> os.system("shutdown /a")
> change_2()
> return
>
> root = tk.Tk()
> setMinutes = IntVar()
> getPass = StringVar()
> timeString = StringVar()
> label_font = ('Verdana', 30)
> root.geometry('260x150+200+200')
> root.title('Timer v1.4')
> root.resizable(0, 0)
>
> L1 = tk.Label(root, text='How much time you have?')
> L1.grid(row=0, columnspan=3, sticky='WE')
>
> L2 = tk.Label(root, textvariable=timeString, font=label_font, bg='white',
>  fg='orange', relief='raised', bd=3)
> L2.grid(row=1, columnspan=3, sticky='WE', padx=5, pady=5)
>
> E1 = tk.Entry(root, textvariable=setMinutes, bg='lightgreen')
> E1.grid(row=2, column=1, padx=5, pady=5)
>
> B1 = tk.Button(root, text='S T A R T', fg='green', bg='black',
> command=startCount)
> B1.grid(row=2, rowspan=2, sticky='NS', column=0, padx=5, pady=5)
>
> E2 = tk.Entry(root, textvariable=getPass, bg='red')
> E2.grid(row=3, column=1, padx=5, pady=5)
>
> B2 = tk.Button(root, text='S T O P', fg='red', bg='black',
> command=stopCount,
> state=tk.DISABLED)
> B2.grid(row=2, rowspan=2, sticky='NS', column=2, padx=5, pady=5)
>
> root.mainloop()
>
>
>
> 2016-11-17 1:03 GMT+01:00 Alan Gauld via Tutor  >:
>
> On 16/11/16 18:48, Freedom Peacemaker wrote:
> > Hi, i need help. I am using Python 3.4 and I have wrote little
> app for
> > windows only ( windows 7 and higher). Its timer and my app
> working but not
> > good. Some people said that i should use after method instead of
> update()
>
> after() executes a function after a delay.
> In your case you could use it to trigger an
> immediate shutdown after the delay elapses.
> But I'm not sure that would be much better
> than doing what you are doing.
>
> The other use 

Re: [Tutor] please help me with after method

2016-11-16 Thread Alan Gauld via Tutor
On 16/11/16 18:48, Freedom Peacemaker wrote:
> Hi, i need help. I am using Python 3.4 and I have wrote little app for
> windows only ( windows 7 and higher). Its timer and my app working but not
> good. Some people said that i should use after method instead of update()

after() executes a function after a delay.
In your case you could use it to trigger an
immediate shutdown after the delay elapses.
But I'm not sure that would be much better
than doing what you are doing.

The other use of after is to avoid loops in
event handlers such as the one you have here.
This allows control to return to the GUI window.

See below...

> When you run app first enter minutes in entry then press start. If you
> first press start your pc will shutdown with no time to stop it

You can fix that by setting a default value for the time.
But you still need to write some code to cancel the shutdown
(by killing the process perhaps?)

> def startCount():
> setTime = setMinutes.get() * 60
> strTime = str(setTime)
> timeSet = ("\""+"shutdown /s /f /t " +strTime+"\"")
> os.system(timeSet)

Up to here is fine but you don't want a long running loop
inside an event handler. Although, in this case, it probably
doesn't run for long, it just counts down very quickly.

Instead you want it to count down  every second or so.

So you want to call a function that displays the time
remaining then calls after() with a delay of 1 second.
The call to after should have the same function in it.
Like so:

def displayCountdown():
# display the time here
# decrement the time by 1 second
# if any time remains:
#call after(1000,displayCountdown) # 1000ms = 1s

Note that after only needs the function name, don't
include any parentheses.

> for t in range(setTime, -1, -1):
> lcd = "{:02d}:{:02d}".format(*divmod(t, 60))
> timeString.set(lcd)
> try:
> root.update()
> except TclError:
> messagebox.showinfo('Info', 'Closing app wont stop timer.')
> return
> time.sleep(1)
> return


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] please help me with after method

2016-11-16 Thread Freedom Peacemaker
Hi, i need help. I am using Python 3.4 and I have wrote little app for
windows only ( windows 7 and higher). Its timer and my app working but not
good. Some people said that i should use after method instead of update()
and nobody told me how. Ive tried many times but i dont know how do it
correctly. Please help me improve my app.

When you run app first enter minutes in entry then press start. If you
first press start your pc will shutdown with no time to stop it

my code:

from tkinter import *
import tkinter as tk
import time, os

def startCount():
setTime = setMinutes.get() * 60
strTime = str(setTime)
timeSet = ("\""+"shutdown /s /f /t " +strTime+"\"")
os.system(timeSet)
for t in range(setTime, -1, -1):
lcd = "{:02d}:{:02d}".format(*divmod(t, 60))
timeString.set(lcd)
try:
root.update()
except TclError:
messagebox.showinfo('Info', 'Closing app wont stop timer.')
return
time.sleep(1)
return

root = tk.Tk()
setMinutes = IntVar()
timeString = StringVar()
label_font = ('Verdana', 30)
root.geometry('210x120+200+200')
root.title('Timer v1.0')
root.resizable(0, 0)

L1 = tk.Label(root, text='How much time you have?')
L1.grid(row=0, columnspan=3, sticky='WE')

L2 = tk.Label(root, textvariable=timeString, font=label_font, bg='white',
 fg='orange', relief='raised', bd=3)
L2.grid(row=1, columnspan=3, sticky='WE', padx=5, pady=5)

E1 = tk.Entry(root, textvariable=setMinutes).grid(row=2, column=1, padx=5,
pady=5)

B1 = tk.Button(root, text='S T A R T', fg='green', bg='black',
command=startCount)
B1.grid(row=2, rowspan=2, sticky='NS', column=0, padx=5, pady=5)

root.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me modify this code so that I can utilize raw_input

2016-10-05 Thread Oscar Benjamin
On 4 October 2016 at 19:11, Alan Gauld via Tutor  wrote:
>> """Define a function sum() and a function multiply() that sums and
>> multiplies (respectively) all the numbers in a list of numbers. For
>> example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4])
>> should return 24."""
>
> 
> I do wish teachers would not ask students to reinvent the wheel.

You may be misunderstanding the teacher's objectives here. Sometimes
Python is used to introduce the concept of programming more generally
rather than specifically to prepare someone for professional
programming using Python. I don't know about you but I came to Python
after a number of other programming languages. Now that I teach
programming I can see that it's important in a first programming
introduction to cover nuts and bolts type algorithmic thinking. sum()
is a good example of an algorithm that most people are already used to
performing on pen and paper making it a good candidate for learning to
use loops and functions.

> Python already has a perfectly good sum() function.

Writing your own sum function helps to understand what actually
happens when using the standard sum function. I do the same thing with
my students in C teaching them how to make their own e.g. strlen
function. I will tell them that strlen exists afterwards but I want
them to understand what the null byte is and writing your own (or just
looking at a) strlen implementation helps with that. Likewise simply
using a function e.g. strcat without understanding its implementation
can lead to segfaults so there can be a relevance in understanding the
implementation even if you don't intend to reimplement something in
your own code. The implications of the implementation of sum are also
non-trivial which is why the stdlib contains at least 3 different sum
functions.

It's great that Python comes with so many functions to do common
tasks. However from personal experience teaching Python as a first
language can lead to the disadvantage that many students become spoilt
programmers. They will learn to assume that there is a function for
exactly what they want and all they ever need to do is ask a precise
question in a search engine and read the first stackoverflow page.
That may be the correct approach for many problems but it isn't
always. A programmer should have the ability to implement basic
algorithms (e.g. sum) for themselves when necessary.

> And both problems become trivial if using functools.reduce()
> 

Different people think in different ways but I reckon most people -
and especially most beginners - would find a loop more straightforward
than reduce. I doubt that the OP is at a stage where using reduce
seems trivial.

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


Re: [Tutor] please help me modify this code so that I can utilize raw_input

2016-10-04 Thread Alan Gauld via Tutor
On 04/10/16 15:04, Richard Koeman wrote:
> I would like to modify this code so that instead of me calling the function
> with the list as shown [1,2,3,4], the user inputs the list with raw_input.
> 

You don't need to modify your code you just need ton write a function
that reads a list from the user. Notice that this can e done by either
repeatedly asking the user to input values until they are done or by
reading a string containing the values and converting the string to a
list of numbers.


> """Define a function sum() and a function multiply() that sums and
> multiplies (respectively) all the numbers in a list of numbers. For
> example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4])
> should return 24."""


I do wish teachers would not ask students to reinvent the wheel.
Python already has a perfectly good sum() function.
And both problems become trivial if using functools.reduce()


> 
> def sum(mylist = [], *args):
>   print mylist
>   sum_of_number = 0
>   for i in mylist:
> sum_of_number += i
>   print "The sum of the digits in your number is %s" %(sum_of_number)

> def multiply(mylist = [], *args):
>   product_of_number = 1
>   for i in mylist:
> product_of_number = product_of_number * i
>   print "The product of the digits in your number is %s"
> %(product_of_number)
> 
> sum([1,2,3,4])
> multiply([1,2,3,4])

Incidentally, notice that the assignment asks you to *return* the
results not print them. This is good practice, keep the printing
separate from the calculation. You can then print the result,
if you wish, with

print( sum([]) )

hth
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] please help me modify this code so that I can utilize raw_input

2016-10-04 Thread Richard Koeman
I would like to modify this code so that instead of me calling the function
with the list as shown [1,2,3,4], the user inputs the list with raw_input.

Thanks in advance


"""Define a function sum() and a function multiply() that sums and
multiplies (respectively) all the numbers in a list of numbers. For
example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4])
should return 24."""

def sum(mylist = [], *args):
  print mylist
  sum_of_number = 0
  for i in mylist:
sum_of_number += i
  print "The sum of the digits in your number is %s" %(sum_of_number)
def multiply(mylist = [], *args):
  product_of_number = 1
  for i in mylist:
product_of_number = product_of_number * i
  print "The product of the digits in your number is %s"
%(product_of_number)

sum([1,2,3,4])
multiply([1,2,3,4])

-- 
This is a staff email account managed by Simcoe Muskoka Catholic District 
School Board.  This email and any files transmitted with it are 
confidential and intended solely for the use of the individual or entity to 
whom they are addressed. If you have received this email in error please 
notify the sender.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] please help me

2010-01-31 Thread Luke Paireepinart
Please reply on-list unless you really need to speak to me off-list.
Use "reply-all" to reply to everyone.

Tutor doesn't work in that you get one of us as a tutor and we help you with
every problem you have.  For this mailing list you e-mail us a specific
problem and everyone collaborates to guide you through it.  When we say
"specific problem" we mean "you have coded a solution that looks to you like
it would work but it doesn't and you're stuck" and then we'll help you
figure out why you're stuck and what you need to do to fix the program.

(P.S. Sorry for the top-post, I'm not sure how to reply in-line to a
forwarded message.)


-- Forwarded message --
From: invincible patriot 
Date: Sun, Jan 31, 2010 at 4:05 AM
Subject: RE: [Tutor] please help me
To: rabidpoob...@gmail.com


 m sorry but i am not asking u to solve these for me rather i send all the
questions to u just to let u know what i want to do n now i m looking
froward for ur guidance so that i can write programme for thhem
i think itz fair enough to ask what should i do, but i am not asking u to
solve them for me
m just looking forward for some help


--
From: rabidpoob...@gmail.com
Date: Sat, 30 Jan 2010 19:39:05 -0600
Subject: Re: [Tutor] please help me
To: invincible_patr...@hotmail.com
CC: tutor@python.org


[snip homework]



please help me


This is a tutor mailing list.  Tutor means we will help you learn, not that
we will write your homework assignments for you for free.  That is the
opposite of learning.

Try all of the programs.  Give us what you have tried and what didn't work,
why you thought it would work, why you think it didn't work, and anything
else helpful (eg. if you get an error message include the whole traceback,
don't paraphrase it.)

In other words, if you don't have code that you've tried and a specific
problem you're having, you're not going to get a reply.  We're busy people,
make it easy for us to help you.

-Luke


--
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up
now.<http://clk.atdmt.com/GBL/go/196390709/direct/01/>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me

2010-01-30 Thread Luke Paireepinart
[snip homework]

>
>
> please help me
>
>
This is a tutor mailing list.  Tutor means we will help you learn, not that
we will write your homework assignments for you for free.  That is the
opposite of learning.

Try all of the programs.  Give us what you have tried and what didn't work,
why you thought it would work, why you think it didn't work, and anything
else helpful (eg. if you get an error message include the whole traceback,
don't paraphrase it.)

In other words, if you don't have code that you've tried and a specific
problem you're having, you're not going to get a reply.  We're busy people,
make it easy for us to help you.

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


[Tutor] please help me

2010-01-30 Thread invincible patriot

hii am stuck in these questions can someone please help me in solving and 
writing programme for these tasks
please help me




1 1.1 Write a Python program with a loop that prints out a sequence of numbers 
as follows:151311...31-1

1.2 Write a small Python program that generates the list of all pairs of 
characters c andits doubling 2  c, where c moves through all the letters of 
the string "foobar" and prints it out.The result will look like:[(’f’, ’ff’), 
(’o’, ’oo’), (’o’, ’oo’), (’b’, ’bb’), (’a’, ’aa’), (’r’, ’rr’)]Hint: use list 
comprehensions.
1.3 Write a small Python program that
1. prints out the length of the 
string’taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu’
2. prints out how many different characters this string contains
3. replaces all the non-’t’ characters in above string with dots ’.’. So, if 
the word were’tattoo’, it would print ’t.tt..’.Hints:
(a) use a function to t-ify the string
(b) there are various ways to construct the string, either using the join 
method or by runninga loop accumulating substrings.
(c) check also out what happens if you apply the conversion list(s) to a string 
s.
2 2.1 Write a function count char(s, c) that takes a string s, and a character 
c and returnshow often the character c appears in the string.For example 
count_char("tattoo", "t") should return 3.

2.2 Write a Python function char_freqency(s)that returns a dictionary which, 
for eachcharacter of s as a key, stores as value how often this character 
appears.For example, char_frequency("tattoo") could return {’a’: 1, ’t’: 3, 
’o’: 2} (the order ofkey:value pairs does not matter here).
Hint: Consider using the function count_char defined in 2.1.
2.3 Write a program that translates a given string (of arbitrary length) of DNA 
bases intothe RNA strand that it will produce. For this, research which DNA 
bases correspond to RNA basesand create a translation table (not an if...else 
clause!) in the Python program. [4 marks]


3 
3.1 consider the following list of base 
sequences:ACGTACCTTACTTACCATATCGTACCTCTTACTCATThe task consists of writing a 
Python program that performs a simple alignment algorithm onthese two strings 
and prints out this alignment in a suitable readable form. Give a brief 
commentexplaining the output format.Hints:1. Matching means the following: for 
a given sequence to be matched, your program should denotewhich bases 
correspond to bases in the reference sequence and which do not; in addition, 
markgaps where the reference sequence contains bases which are not present in 
the sample sequence.For a given sample sequence, your matching algorithm will 
attempt to match as many basesas possible to those of the reference sequence.2. 
This is a difficult assignment. Do not attempt it before you have solved the 
others.3. For this purpose, you are allowed to research and implement publicly 
documented versions ofthe Needleman-Wunsch algorithm or similar algorithms 
(however, make sure that you refer-ence them properly!). Also make sure that 
your program prints out the matches/mismatchesbetween the sequences. You should 
demonstrate at least two different alignments by usingdifferent gap 
penalties.Instead of following this hint, you can develop an alternative 
solution to the matching problem,e.g. based on the Levenshtein distance.


please help me
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/196390706/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me

2009-06-18 Thread Emile van Sebille

On 6/18/2009 1:30 AM suzee Eslam said...

to every one help me please ..
i need the code to do chatting by python in mobiles over bluetooth 
technology .. i need it please if any one know it send it to me as soon 
as possible..

thanks for all.


Maybe this will get you started...

http://www.mobilenin.com/mobilepythonbook/examples/057-btchat.html

Emile

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] please help me

2009-06-18 Thread suzee Eslam
to every one help me please ..
i need the code to do chatting by python in mobiles over bluetooth technology 
.. i need it please if any one know it send it to me as soon as possible..
thanks for all.


  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me

2007-04-13 Thread Greg Perry
Let no good deed go unpunished!

-Original Message-
From: Daniel Yoo
Date: Friday, Apr 13, 2007 8:24 pm
Subject: Re: [Tutor] please help me

> If this is homework, please tell your teacher I helped - I need the 
> extra credit.
>
>Please avoid giving homework answers like this.  Rather than actually help 
>the person, it can do harm, because it encourages a lazy attitude toward 
>solving problems.



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me

2007-04-13 Thread Daniel Yoo
> If this is homework, please tell your teacher I helped - I need the 
> extra credit.

Please avoid giving homework answers like this.  Rather than actually help 
the person, it can do harm, because it encourages a lazy attitude toward 
solving problems.
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me!

2007-04-12 Thread Ben Sherman
You

On 4/12/07, suryo agung <[EMAIL PROTECTED]> wrote:
> pleate tell me how to make
>
> input number=4
> result
>
> 1
> 22
> 333
> 
>
> in python
> please give me your answer.

input_number = 4

for i in range(1,input_number + 1):
  print str(i) * i

If this is homework, please tell your teacher I helped - I need the
extra credit.
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me!

2007-04-12 Thread Kent Johnson
suryo agung wrote:
> pleate tell me how to make
> 
> input number=4
> result
> 
> 1
> 22
> 333
> 
> 
> in python
> please give me your answer.

This looks a lot like homework to me. What have you tried? What have you 
learned?

Kent
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] please help me!

2007-04-12 Thread suryo agung
pleate tell me how to make

input number=4
result

1
22
333


in python
please give me your answer.
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please help me get started on how to program useing python 2.4!!! (fwd)

2005-03-11 Thread Danny Yoo
[Forwarding to [EMAIL PROTECTED]  Sorry about the repetition.]


-- Forwarded message --
Date: Fri, 11 Mar 2005 17:18:03 EST
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] Please help me get started on how to program useing
python 2.4!!!

ok heres where i got the for,in, and
rangehttp://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html
and i tryed what it say and the...print "hello world"..and the next step
works...print "here are the ten numbers from 0 to 9".but the next dose 
not...
for i in range(10):
  print i,..


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please help me get started on how to program useing python 2.4!!! (fwd)

2005-03-11 Thread Danny Yoo
[Forwarding to [EMAIL PROTECTED]  Please use your email client's
"Reply-to-all" feature whenever you're replying to messages on the tutor
list.  Otherwise, no one else gets to see your questions.]


-- Forwarded message --
Date: Fri, 11 Mar 2005 17:07:15 EST
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] Please help me get started on how to program useing
python 2.4!!!

ok i understand some of that like the = things being ture or false but i am
not realy wanting to know if its = or not, i was just trying to figer out how
to make a progarm or just program... and figer out the language..lol.if you
can help me do that i would
be realy thankful

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please help me get started on how to program useing python 2.4!!!

2005-03-11 Thread Brian van den Broek
Danny Yoo said unto the world upon 2005-03-11 16:07:
On Fri, 11 Mar 2005 [EMAIL PROTECTED] wrote:

When we ask: "Is the number 'one' greater than the number 'two'?", Python
is telling us "No!" by giving us back the value 'False'.  Whenever we ask
Python a question that's a yes/no sort of thing, Python will respond with
a value like 'True' or 'False'.
We can also compare strings to see if a word is "bigger" than another
word, based on where it might be located in a dictionary.  For example:
###
"application" < "applied"
True
"applied" < "application"
False
###
A slight refinement of what Danny said: for strings, comparisons 
determine which string is "bigger" based on a concept of `dictionary 
order' where  x is `bigger' than y if it comes later in a dictionary 
which puts uppercase letters before lower case ones.

Hence:
>>> 'z' < 'a'
False
>>> 'Z' < 'a'
True
>>>
Best,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please help me get started on how to program useing python 2.4!!!

2005-03-11 Thread Danny Yoo


On Fri, 11 Mar 2005 [EMAIL PROTECTED] wrote:

> OK i have learned that on the python shell if you put, print "some
> message" the output is, some message

Hi Jeff,


Ok, yes, that looks right.  Let me do that myself:

###
>>> print "hello world"
hello world
###

(The '>>>' thing is what the Python shell prints out, as a "prompt" to
tell me that it's ready to read more commands).




> and if you put, type > "some message" the output is, true
>
> and if you put, type< "some message" the output is, false



H!  Let me make sure I understand:  are you doing this?

###
>>> type < "some message"
False
>>>
>>>
>>> type > "some message"
True
###

What we are asking Python here is actually a bit weird: we are asking it
to compare the 'type' function to see if it's either "less than" or
"greater than" the string 'some message'.

Did you get these expressions from some online tutorial?  If so, point us
to that tutorial, so I can bonk the author.  *grin*

How are you learning Python?  Are you going through a book, or through
some web page tutorial?


[Note for advanced users: I know that Python will give something that will
return some consistent result.  According to:

http://www.python.org/doc/ref/comparisons.html

"Most other types compare unequal unless they are the same object; the
choice whether one object is considered smaller or larger than another one
is made arbitrarily but consistently within one execution of a program."

So what Jeff is seeing is a completely arbitrary result, and it's not even
guaranteed to be the same between program executions!  That's why I think
it's the wrong thing to show because it's hard to explain.  And I think
it's a terrible idea to show something like that to a beginner since it's
not something that a sensible programmer would normally do anyway.]



Jeff, I think it might make more sense to compare two things that are the
same kind of thing.  For example, it should make more sense to compare two
numbers to see if one is bigger than the other:

###
>>> 1 > 2
False
>>> 2 > 1
True
###

When we ask: "Is the number 'one' greater than the number 'two'?", Python
is telling us "No!" by giving us back the value 'False'.  Whenever we ask
Python a question that's a yes/no sort of thing, Python will respond with
a value like 'True' or 'False'.


We can also compare strings to see if a word is "bigger" than another
word, based on where it might be located in a dictionary.  For example:

###
>>> "application" < "applied"
True
>>> "applied" < "application"
False
###


In technical terms, we are giving Python expressions that "evaluate" to a
"boolean" value: we're asking Python questions, and it's saying True or
False.  Does this make sense so far?  If not, please continue to ask
questions, and we'll try to show things more clearly.



> And if you put, for, in, or and it turns orange like print dose but I
> don't know why?

If you're using IDLE, then stuff that shows up as orange when it's a
special kind of "keyword".

A keyword is a word that Python knows is a special word.  When you learn
more about Python, you'll see a few more of these keywords.  The orange
coloring is there just to make them stand out from the rest of your
program, and doesn't have any other significance, other than just being
colorful.  *grin*


If you have questions on any of this, please feel free to ask.  Best of
wishes to you!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Please help me get started on how to program useing python 2.4!!!

2005-03-11 Thread Jeff420harris00
OK i have learned that on the python shell if you put, print "some message"
the output is, some message   and if you put, type> "some message"
the output is, true    and if you put, type< "some message"
the output is, false   And if you put, for, in, or and it turns orange like print dose but I don't know why? 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help me improve my python style

2005-01-14 Thread Alan Gauld
> # This program simulates the random branching and extinction of
linages.
> # It also mutates a series of characters representing morphology at
> each branch point
> # The program replicates the program first described by D.M. Raup
and
> S.G. Gould
> # 1974 Systematic Zoology 23: 305-322.
> # written by Vincent Wan with help from tutor@python.org

Put the above set of comments in triple quotes and it will
become a *docstring* and hence accessible via Pythons help()
function...

> import random
>
> debug = 0# turns debug diagnostic printing on = 1 or off = 0
>
> #constants that control the simulation
> max_linages = 201# the number of linage to be evolved + 1
> branching_probablity = .1
> extinction_probablity = .1
> mutation_rate = .5

Constants should be in UPPER_CASE by convention.

> # initalize
> living_linages = [[0, 0, 0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]] # the
> ancestor
> dead_linages = []
> tree = "*0*"
> time = 0
> next_linage = 0
>
> def Mutate_morphology(a_morphology, rate):

the fashion for function naming is to separewt words
with capitals so this would be mutateMorphology(...)
Names starting upper case are conventionally classes.
So a Python reader may think the function call is a
class instatiation as it is.

>  "Each morphological character has a rate chance it is increased
or
> decreased by 1"
>  a_morphology = a_morphology[:]
>  character = 0
>  while character < len(a_morphology):
>  if random.random() <= rate:
>  if random.random() < .5:

.5 would be clearer as 0.5, the point on its own is easily missed.

>   a_morphology[character] =
a_morphology[character] - 1
>  else:a_morphology[character] = a_morphology[character]
+ 1

You could use += and -+ here to save a wee bit of space.

>  character += 1
>  return a_morphology
>
> def Braching(debug, next_linage, time, living_linages,
mutation_rate,
> tree):
>  "With branching_probablity creates a new linage, mutates its
> morphology, and updates tree."
>  counter = 0
>  while counter < len(living_linages):
>  if random.random() < branching_probablity:
>  # creates new linage
>  next_linage += 1
>  new_linage = [next_linage, time, 0,
> Mutate_morphology(living_linages[counter][3], mutation_rate)]

better to line this up with the other parameters:
   new_linage = [next_linage, time, 0,

Mutate_morphology(living_linages[counter][3],
  mutation_rate)]

it keeps the block structure clear.

>  living_linages.append(new_linage)
>  # updates linage tree
>  target = '*' + str(living_linages[counter][0]) + '*'
>  replacement = '(' + target + ',*' + str(new_linage[0])
+
> '*)'

You could use string formatting to do both lines in one:

replacement = "(*%s*,*%s*)" %  (living_linages[counter][0],
new_linage[0])

it will be faster too.

>  tree = tree.replace(target, replacement)

Ah, but here you use both bits Ok, but you could still use
formatting to create the two strings.

>  counter += 1
>  if debug: print 'at time ', time, ' living_linages: ',
> [linage[0] for linage in living_linages]
>  return (next_linage, living_linages, tree)
>
> def Extinction(debug, extinction_probablity, living_linages, time,
> dead_linages):
>  "With extinction_probablity kills living species and adds them
to
> the dead list"
>  counter = 0
>  while counter < len(living_linages):
>  if random.random() < extinction_probablity:
>  newly_dead = living_linages[counter]
>  newly_dead[2] = time
>  dead_linages.append(newly_dead)
>  living_linages.remove(living_linages[counter])
>  if len(living_linages) == 0: break# when the last
> living_linages goes extinct exit
>  counter += 1

there may be a subtle bug here. IF you remnove an entry above
then all the elements shuffle up one. If you now increment
counter you will in effect step over one entry without
checking it. Is that what you want?


>  if debug: print 'at time ', time, ' dead_linages : ',
[linage[0]
> for linage in dead_linages]
>  return (living_linages, dead_linages)
>
> def Print_results(next_linage, max_linages, living_linages,
> dead_linages, tree):
>  "prints number of linages, the data about the linages living
and
> dead, and the tree"
>  if next_linage < max_linages:
>  print '\nall extinct with only ', next_linage + 1, ' linage
of
> ', max_linages
>  else:
>  print '\n', max_linages - 1, ' linages evolved'
>  print '\nliving linages:'
>  for each in living_linages:
>  print 'linage', each[0], 'born', each[1], 'morphology:',
each[3]
>  print '\nextinct linages: '
>  for each in dead_linages:
>  print 'linage', each[0], 'born', each[1], '- died', each[2]
>  print 'morphology:

[Tutor] please help me improve my python style

2005-01-13 Thread Vincent Wan
I have my first python program working (thank you for the help all).  
Will anyone give me hints on how my program could be improved and on  
how I could improve my programing style?

I want it to be well written as it can be but also as close to self  
documenting and understandable to the average non-programer biologist.

Here is the first draft of my code:
# This program simulates the random branching and extinction of linages.
# It also mutates a series of characters representing morphology at  
each branch point
# The program replicates the program first described by D.M. Raup and  
S.G. Gould
# 1974 Systematic Zoology 23: 305-322.
# written by Vincent Wan with help from tutor@python.org

import random
debug = 0# turns debug diagnostic printing on = 1 or off = 0
#constants that control the simulation
max_linages = 201# the number of linage to be evolved + 1
branching_probablity = .1
extinction_probablity = .1
mutation_rate = .5
# initalize
living_linages = [[0, 0, 0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]] # the  
ancestor
dead_linages = []
tree = "*0*"
time = 0
next_linage = 0

def Mutate_morphology(a_morphology, rate):
"Each morphological character has a rate chance it is increased or  
decreased by 1"
a_morphology = a_morphology[:]
character = 0
while character < len(a_morphology):
if random.random() <= rate:
if random.random() < .5:
 a_morphology[character] = a_morphology[character] - 1
else:a_morphology[character] = a_morphology[character] + 1
character += 1
return a_morphology

def Braching(debug, next_linage, time, living_linages, mutation_rate,  
tree):
"With branching_probablity creates a new linage, mutates its  
morphology, and updates tree."
counter = 0
while counter < len(living_linages):
if random.random() < branching_probablity:
# creates new linage
next_linage += 1
new_linage = [next_linage, time, 0,  
Mutate_morphology(living_linages[counter][3], mutation_rate)]
living_linages.append(new_linage)
# updates linage tree
target = '*' + str(living_linages[counter][0]) + '*'
replacement = '(' + target + ',*' + str(new_linage[0]) +  
'*)'
tree = tree.replace(target, replacement)
counter += 1
if debug: print 'at time ', time, ' living_linages: ',  
[linage[0] for linage in living_linages]
return (next_linage, living_linages, tree)

def Extinction(debug, extinction_probablity, living_linages, time,  
dead_linages):
"With extinction_probablity kills living species and adds them to  
the dead list"
counter = 0
while counter < len(living_linages):
if random.random() < extinction_probablity:
newly_dead = living_linages[counter]
newly_dead[2] = time
dead_linages.append(newly_dead)
living_linages.remove(living_linages[counter])
if len(living_linages) == 0: break# when the last  
living_linages goes extinct exit
counter += 1
if debug: print 'at time ', time, ' dead_linages : ', [linage[0]  
for linage in dead_linages]
return (living_linages, dead_linages)

def Print_results(next_linage, max_linages, living_linages,  
dead_linages, tree):
"prints number of linages, the data about the linages living and  
dead, and the tree"
if next_linage < max_linages:
print '\nall extinct with only ', next_linage + 1, ' linage of  
', max_linages
else:
print '\n', max_linages - 1, ' linages evolved'
print '\nliving linages:'
for each in living_linages:
print 'linage', each[0], 'born', each[1], 'morphology:', each[3]
print '\nextinct linages: '
for each in dead_linages:
print 'linage', each[0], 'born', each[1], '- died', each[2]
print 'morphology:', each[3]
tree = tree.replace('*','')
print '\ntree (in New Hampshire form: )', tree

# main loop
while next_linage < max_linages:
# handles branching
(next_linage, living_linages, tree) = Braching(debug, next_linage,  
time, living_linages, mutation_rate, tree)
# handles extinction
(living_linages, dead_linages) = Extinction(debug,  
extinction_probablity, living_linages, time, dead_linages)
if len(living_linages) == 0: break# when the last  
living_linages goes extinct exit
time += 1

Print_results(next_linage, max_linages, living_linages, dead_linages,  
tree)

Thank you,
Vincent
 
--
PhD Candidate
Committee on the Conceptual and Historical Studies of Science
University of Chicago

PO Box 73727
Fairbanks, AK 99707
wan AT walrus DOT us (change CAPS to @ and . )
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor