Re: [Tutor] (no subject)

2005-09-24 Thread Danny Yoo
On Sat, 24 Sep 2005 [EMAIL PROTECTED] wrote: > How would I get the following program to accept inputs of exam scores > from 0-100 with A being 100-90, B being 89-80, C being 79-70, D being > 69-60, and F being everything less than 60? Hello, Are you familiar with "if/elif/else"? These "contr

Re: [Tutor] printing an acronym

2005-09-24 Thread Danny Yoo
On Sat, 24 Sep 2005 [EMAIL PROTECTED] wrote: > How could I get the following to print out an acronym for each phrase > entered such as if I entered random access memory it word print out RAM? Hello, Just out of curiosity, are you already familiar with Python's "lists"? If so, then you might

Re: [Tutor] numbers from a name

2005-09-24 Thread Goofball223
How could I change the program to accept something like: John Bob Zelle Python or Kip Rada? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] numbers from a name

2005-09-24 Thread ZIYAD A. M. AL-BATLY
On Sat, 2005-09-24 at 23:50 -0400, [EMAIL PROTECTED] wrote: > Hello Hi Goofball... > > with the following program I would like it to be able to take a > person's name and then assign values to each letter and come up with > a sum of all the letters in the name. for example if I entered bob. i > w

[Tutor] numbers from a name

2005-09-24 Thread Goofball223
Hello with the following program I would like it to be able to take a person's name  and then assign values to each letter and come up with a sum of all the letters in the name. for example if I entered bob. i would like the program to be able to print bob and then print the total of bob which wou

Re: [Tutor] (no subject)

2005-09-24 Thread Liam Clarke
I'd also like to mention that input() is bad, as you can enter Python statements and it'll execute them. For instance, entering "sys.exit()" would cause your programme to try and call sys.exit(), which if the sys module had been imported, would quit. You can do far more malevolent things than that

[Tutor] creating strings

2005-09-24 Thread Goofball223
Hello How would I get the following program to accept inputs of exam scores from 0-100 with A being 100-90, B being 89-80, C being 79-70, D being 69-60, and F being everything less than 60? import string def main():   scores = ["F", "D", "C", "B", "A"]   g = input("Enter a score number (0-10

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread Kent Johnson
Your method signatures are off. Should be def getA(self): def setA(self, value) So when you write self.a = 20 you are passing self as the um parameter. Actually I don't know why you don't get an exception for passing too many arguments? And you don't need setattr, just write Strange.a = propert

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread Kent Johnson
Liam Clarke wrote: >>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698 > > > Thanks Kent. Just looking at that above recipe, I'm not too sure how > the @ decorators work. >>From what I understand, it defines would turn apply() into a function > that returns the various get/sets? OK,

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread Liam Clarke
Ooer, Well, I got setattr() and property() working together nicely, but with a weird side effect. class Strange(object): def getA(um, self): print "What is", um return self.__a def setA(um, self, value): print um, "turns up here as well." self.__a = value

Re: [Tutor] (no subject)

2005-09-24 Thread bob
At 03:29 PM 9/24/2005, [EMAIL PROTECTED] wrote: Hello How would I get the following program to accept inputs of exam scores from 0-100 with A being 100-90, B being 89-80, C being 79-70, D being 69-60, and F being everything less than 60? Many solutions are available. One could use an if stateme

Re: [Tutor] printing an acronym

2005-09-24 Thread R. Alan Monroe
> Hello > How could I get the following to print out an acronym for each phrase > entered such as if I entered random access memory it word print out RAM? > import string > def main(): > phrase = (raw_input("Please enter a phrase:")) > acr1 = string.split(phrase) > acr2 = string

[Tutor] printing an acronym

2005-09-24 Thread andrade1
Hello How could I get the following to print out an acronym for each phrase entered such as if I entered random access memory it word print out RAM? import string def main(): phrase = (raw_input("Please enter a phrase:")) acr1 = string.split(phrase) acr2 = string.capwords(phrase

[Tutor] (no subject)

2005-09-24 Thread Goofball223
Hello How would I get the following program to accept inputs of exam scores from 0-100 with A being 100-90, B being 89-80, C being 79-70, D being 69-60, and F being everything less than 60? import string def main():    scores = ["F", "D", "C", "B", "A"]    g = input("Enter a score number (0-

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread Liam Clarke
Hi, > You might want to learn more about the whole property mechanism then. > property() is actually a bit of sugar over a deeper mechanism. Also there is > an interesting idiom for creating properties using @apply (in Python 2.4) - > look for Benji York's comment in this recipe: > http://aspn

Re: [Tutor] File mode r+

2005-09-24 Thread Shitiz Bansal
Hi, How do i proceed if i am not sure about the number of characters in the fist two lines and want to write in the third line.is there a way to skip two lines and write on the third?? Also could anyone explain why the readline() did not work. according to what i understand it should.   shitizbob

Re: [Tutor] Sum of List Elements

2005-09-24 Thread Luke Jordan
Thanks for the help everyone, for answering a simple question and pointing me toward more resources.On 9/24/05, bob < [EMAIL PROTECTED]> wrote:At 08:11 AM 9/24/2005, Luke Jordan wrote:>Hi All, >>I have spent an embarrassingly large amount of time trying to solve what>on its face seems like a simple

Re: [Tutor] Sum of List Elements

2005-09-24 Thread bob
At 08:11 AM 9/24/2005, Luke Jordan wrote: >Hi All, > >I have spent an embarrassingly large amount of time trying to solve what >on its face seems like a simple problem. > >I have a list of intergers, and I want to assign the sum of the intergers >in the list to a variable. There are only interger

Re: [Tutor] Stupid newbie question

2005-09-24 Thread grouchy
As long as you are using IDLE, why not let it handle indentation for you?  This could very well be a dumb question, and if it is, well, excuse me :)On 9/23/05, Valone, Toren W. <[EMAIL PROTECTED]> wrote: I am trying to noodle thru classes with python and I built the followingclassimport timeclass

Re: [Tutor] File mode r+

2005-09-24 Thread bob
At 01:11 AM 9/24/2005, Shitiz Bansal wrote: >Hi, >I want to update a textfile using the r+ file mode. >contents of file: > >abcd >efgh >ijkl >mnop >qrst >uvwx >yx12 > >my scripts is: > >file1=open("aa.txt",'r+') Instead of readline, use skip to position the file to where you want to overwrite it.

Re: [Tutor] Sum of List Elements

2005-09-24 Thread grouchy
Also, the built in function sum(): total = sum(list) Which is probably the One Obvious Way since 2.3, if I had to guess.  On 9/24/05, R. Alan Monroe < [EMAIL PROTECTED]> wrote:> Hi All,> I have spent an embarrassingly large amount of time trying to solve what on > its face seems like a simple prob

Re: [Tutor] Sum of List Elements

2005-09-24 Thread wkranec
how about sum()? >>> sum(range(30)) 435 -Bill ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Binary 2 text & text 2 binary

2005-09-24 Thread Joseph Quigley
Hi, >From: "R. Alan Monroe" <[EMAIL PROTECTED]> > >They're easy. Just put stuff in square brackets with commas between. > >mycoollist = [1,5,9,3,6,9,2,6] >mystringlist = ['a', 'u', 'e', 'b', 'd', 'h', 'q', 't'] > > Ah sorry I forgot to say: I know how to print them but that's about it. >Can you

Re: [Tutor] Sum of List Elements

2005-09-24 Thread R. Alan Monroe
> Hi All, > I have spent an embarrassingly large amount of time trying to solve what on > its face seems like a simple problem. > I have a list of intergers, and I want to assign the sum of the intergers in > the list to a variable. There are only intergers in the list. > The best I have been ab

[Tutor] Sum of List Elements

2005-09-24 Thread Luke Jordan
Hi All, I have spent an embarrassingly large amount of time trying to solve what on its face seems like a simple problem. I have a list of intergers, and I want to assign the sum of the intergers in the list to a variable. There are only intergers in the list. The best I have been able to do so

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread Kent Johnson
mailing list wrote: > Hi Kent, > > > >> >>> class foo(object): >> ... __slots__ = ['x', 'y'] >> ... >> >>> f=foo() >> >>> f.x=1 >> >>> f.y=2 >> >>> f.z=3 >>Traceback (most recent call last): >> File "", line 1, in ? >>AttributeError: 'foo' object has no attribute 'z' >> >>Take a look at >>htt

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread mailing list
Hi Kent, > > >>> class foo(object): > ... __slots__ = ['x', 'y'] > ... > >>> f=foo() > >>> f.x=1 > >>> f.y=2 > >>> f.z=3 > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'foo' object has no attribute 'z' > > Take a look at > http://www.python.org/2.2.3/des

Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread Kent Johnson
mailing list wrote: > Hi all, > > I'm just looking for a quick runthrough on the differences between new > style classes and the old ones, and how to use the new ones. > > Also, how exactly do you use __slots__? I've got a 6000 object > collection, and apparently using __slots__ will save memory,

Re: [Tutor] Binary 2 text & text 2 binary

2005-09-24 Thread Poor Yorick
Pujo Aji wrote: > If your symbol are specific it is better to use dictionary. > then if the user give an input you can take character by character and > translate into your binary. > This is the code textTobinary: > mydic = {'A' : "0101", 'B' : "0110", 'C' : "0111"} > strinput

Re: [Tutor] Help with pi and the math module.

2005-09-24 Thread Pujo Aji
hi,   if you use : import math you can type: diameter * math.pi   if you use from math import * you can type: diameter * pi   Cheers, pujo  On 9/24/05, Nathan Pinno <[EMAIL PROTECTED]> wrote: Hi all,   I need help with pi and the math module. I had import math at the top of a program, but when it

Re: [Tutor] Binary 2 text & text 2 binary

2005-09-24 Thread Pujo Aji
If your symbol are specific it is better to use dictionary. then if the user give an input you can take character by character and translate into your binary. This is the code textTobinary:     mydic = {'A' : "0101", 'B' : "0110", 'C' : "0111"}    strinput = 'ABBC'    result = [mydic[x]

[Tutor] File mode r+

2005-09-24 Thread Shitiz Bansal
Hi, I want to update a textfile using the r+ file mode. contents of file: abcd efgh ijkl mnop qrst uvwx yx12 my scripts is: file1=open("aa.txt",'r+') file1.readline() file1.readline() file1.write("1234\n") file1.close() This should replace the third line with 1234. However it does nothing. Mor