Dear Michael
Overall I see a few problems.
0. Functions should return values. Not print them
1. Why use enumerate? The code is not using the index anyway
2. The following line appears wrong.
new_output = ' '.join(user_input)
3. This line has a very buggy possibility.
On 2012/02/08 07:56 AM, Michael Lewis wrote:
I want to find all digits in a string and then increment those digits
by 1 and then return the same string with the incremented digits.
I've tried the following code, but I am getting the following error.
How do I do this properly?
def AlterInput(
I want to find all digits in a string and then increment those digits by 1
and then return the same string with the incremented digits.
I've tried the following code, but I am getting the following error. How do
I do this properly?
def AlterInput(user_input):
print user_input
new_output =
On 07/02/12 19:45, Michael Lewis wrote:
As the instructions in the message you posted say...
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."
And also please delete all the irrelevant stuff, it's almost impossible
to spot the
On 07/02/12 19:32, Gregory, Matthew wrote:
class Statistics(object):
STAT = {
'MEAN': get_mean,
'SUM': get_sum,
}
...
if __name__ == '__main__':
spam = Statistics(4, 3)
print spam.get_stat('mean')
print spam.get_stat('sum')
Since a class is effect
On Tue, Feb 7, 2012 at 2:32 PM, Gregory, Matthew
wrote:
> Hi list,
>
> I'm trying to understand how to use a class-level dictionary to act as a
> switch for class methods. In the contrived example below, I have the
> statistic name as the key and the class method as the value.
>
> class Statist
On Tue, Feb 7, 2012 at 10:57 AM, wrote:
> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>t
Hi list,
I'm trying to understand how to use a class-level dictionary to act as a switch
for class methods. In the contrived example below, I have the statistic name
as the key and the class method as the value.
class Statistics(object):
STAT = {
'MEAN': get_mean,
'SUM': ge
Do Not Use (no subject) as a subject!
Read the manual before asking questions like this. If you do not
understand the documentation tell us what you do not understand.
On 2/7/2012 1:50 PM, Debashish Saha wrote:
for i in range(1, 8):
print(i)
if i==3:
break
else:
print
On 2/7/2012 1:57 PM, Sarma Tangirala wrote:
Anyway, I was wondering about this, if internally pow() actually uses
**. :P
>>> from dis import dis
>>> dis(lambda a,b:a**b)
1 0 LOAD_FAST0 (a)
3 LOAD_FAST1 (b)
6 BINARY_POWE
Steven D'Aprano wrote:
> Peter Otten wrote:
>> Garland W. Binns wrote:
>>
>>> Could someone please tell me a common or semi-frequent scenario in which
>>> a person would use a backspace escape sequence?
>>
>> Does
>>
>> $ python -c 'print "this is b\bbo\bol\bld\bd"' | less
>>
>> qualify? If yo
On Tue, Feb 7, 2012 at 1:50 PM, Debashish Saha wrote:
> for i in range(1, 8):
> print(i)
> if i==3:
> break
> else:
> print('The for loop is over')
>
>
> Output:
> 1
> 2
> 3
>
> Question:but after breaking the for loop why the else command could not work?
Because that's the way a
On 02/07/2012 01:57 PM, Sarma Tangirala wrote:
On 8 February 2012 00:01, Steven D'Aprano wrote:
Sarma Tangirala wrote:
Is is better to use pow() against **?
Advantages of **
- it is shorter to type x**y vs pow(x, y)
- being an operator, it is slightly faster than calling a function
- you
On Tue, Feb 7, 2012 at 7:50 PM, Debashish Saha wrote:
> for i in range(1, 8):
> print(i)
> if i==3:
> break
> else:
> print('The for loop is over')
>
>
> Output:
> 1
> 2
> 3
>
> Question:but after breaking the for loop why the else command could not work?
>
because the else state
Debashish Saha wrote:
> for i in range(1, 8):
> print(i)
> if i==3:
> break
> else:
> print('The for loop is over')
> Output:
> 1
> 2
> 3
>
> Question:
>
> but after breaking the for loop why the else loop could not work?
The else suite is not invoked because that's the way
On 02/07/2012 01:52 PM, Debashish Saha wrote:
for i in range(1, 8):
print(i)
if i==3:
break
else:
print('The for loop is over')
Output:
1
2
3
Question:
but after breaking the for loop why the else loop could not work?
It works fine. The else clause of a for loop exe
On 8 February 2012 00:01, Steven D'Aprano wrote:
> Sarma Tangirala wrote:
>
> Is is better to use pow() against **?
>>
>
>
> Advantages of **
>
> - it is shorter to type x**y vs pow(x, y)
> - being an operator, it is slightly faster than calling a function
> - you can't monkey-patch it
>
> Disad
for i in range(1, 8):
print(i)
if i==3:
break
else:
print('The for loop is over')
Output:
1
2
3
Question:
but after breaking the for loop why the else loop could not work?
___
Tutor maillist - Tutor@python.org
To unsubscribe or c
for i in range(1, 8):
print(i)
if i==3:
break
else:
print('The for loop is over')
Output:
1
2
3
Question:but after breaking the for loop why the else command could not work?
___
Tutor maillist - Tutor@python.org
To unsubscribe or
On 07/02/12 17:19, Garland W. Binns wrote:
Could someone please tell me a common or semi-frequent scenario in which
a person would use a backspace escape sequence?
Do you mean backspace specifically or do you really mean backslash?
In other words are you looking for a use of literal backspaces
Sarma Tangirala wrote:
Is is better to use pow() against **?
Advantages of **
- it is shorter to type x**y vs pow(x, y)
- being an operator, it is slightly faster than calling a function
- you can't monkey-patch it
Disadvantages of **
- being an operator, you can't directly use it as a fun
On 07/02/12 16:54, Sarma Tangirala wrote:
Is is better to use pow() against **?
I suspect ** will be faster since it doesn't have the function
call overhead.
But I haven't tried timing it. Feel free to do some tests and find out.
Let us know how you get on!
--
Alan G
Author of the Learn to
Peter Otten wrote:
Garland W. Binns wrote:
Could someone please tell me a common or semi-frequent scenario in which a
person would use a backspace escape sequence?
Does
$ python -c 'print "this is b\bbo\bol\bld\bd"' | less
qualify? If you are using (e. g.) Linux this technique is used to sh
Garland W. Binns wrote:
> Could someone please tell me a common or semi-frequent scenario in which a
> person would use a backspace escape sequence?
Does
$ python -c 'print "this is b\bbo\bol\bld\bd"' | less
qualify? If you are using (e. g.) Linux this technique is used to show some
text in bo
Could someone please tell me a common or semi-frequent scenario in which a
person would use a backspace escape sequence?
Thanks,
Garland
--
Sent via Mobile
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http:
On Tue, Feb 7, 2012 at 5:41 AM, Steven D'Aprano wrote:
> myles broomes wrote:
>>
>> Im trying to code a program where the user enters a message and it is
>> returned backwards. Here is my code so far:
>> message = input("Enter your message: ")
>> backw = ""
>> counter = len(message)
>> while mes
On 7 February 2012 13:49, Alan Gauld wrote:
> On 07/02/12 01:01, Nate Lastname wrote:
>
>> Exponents ... are **(or ^)
>>
>
> Not quite the ^ operator is a bitwise XOR...
>
> >>> 2^2
> 0
> >>> 2^1
> 3
>
> pow() is the other way to do exponents.
>
>
Is is better to use pow() against **?
> --
> Al
On 07-Feb-12 03:15, Steven D'Aprano wrote:
Steve Willoughby wrote:
If you need lots of precision, you might consider using the decimal
class. It'll cost you speed vs. the native floating-point type but
won't cause you round-off errors.
I'm afraid that's not correct. Decimal is still subject to
Col,
I think you wrote to me personally by accident, instead of to the Tutor list.
Nothing you said seems to be private, so I've taken the liberty of answering
back on the list.
col speed wrote:
Just an idea - I'm not an expert by any means, just a dabbler, but:
many years ago, when I was l
Steve Willoughby wrote:
On 06-Feb-12 07:25, Kapil Shukla wrote:
i tried writing a small code to calculate option price using the
binomial tree model. I compared my results with results of the same
program in excel. There seems to be a minor difference due to decimal
precision as excel is using 1
myles broomes wrote:
Im trying to code a program where the user enters a message and it is returned
backwards. Here is my code so far:
message = input("Enter your message: ")
backw = ""
counter = len(message)
while message != 0:
backw += message[counter-1]
counter -= 1
print(backw
I just realized my first email was not very self explanatory, so let me
start over.
My system is Windows XP Professional, with Python 2.5, and the library
I'm experiencing trouble with is pyshp, available (single version for
all systems) here :
http://code.google.com/p/pyshp/
Here is the corre
On 07/02/12 01:01, Nate Lastname wrote:
Exponents ... are **(or ^)
Not quite the ^ operator is a bitwise XOR...
>>> 2^2
0
>>> 2^1
3
pow() is the other way to do exponents.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
33 matches
Mail list logo