Re: print("%.2f" % total)

2015-11-21 Thread Frank Millman
"Cai Gengyang" wrote in message news:d34dc21b-fe74-40fc-9b54-c37110529...@googlegroups.com... meal = 44.50 tax = 0.0675 tip = 0.15 meal = meal + meal * tax total = meal + meal * tip print("%.2f" % total) What do the lines inside the parentheses in this statement print("%.2f" % total) mean

Re: print("%.2f" % total)

2015-11-21 Thread Chris Angelico
On Sun, Nov 22, 2015 at 5:30 PM, Cai Gengyang wrote: > What do the lines inside the parentheses in this statement print("%.2f" % > total) mean ? > > What does "%.2f" % total represent ? > This is called "percent formatting" or "printf-style formatting". It's a means of formatting a tuple of valu

Re: print("%.2f" % total)

2015-11-21 Thread Stephane Wirtel
print the two digits after the point. On 11/21, Cai Gengyang wrote: > > meal = 44.50 > tax = 0.0675 > tip = 0.15 > > meal = meal + meal * tax > total = meal + meal * tip > > print("%.2f" % total) > > What do the lines inside the parentheses in this statement print("%.2f" % > total) mean ?

print("%.2f" % total)

2015-11-21 Thread Cai Gengyang
meal = 44.50 tax = 0.0675 tip = 0.15 meal = meal + meal * tax total = meal + meal * tip print("%.2f" % total) What do the lines inside the parentheses in this statement print("%.2f" % total) mean ? What does "%.2f" % total represent ? Thanks alot ... Gengyang -- https://mail.python.org

Re: What is a function parameter =[] for?

2015-11-21 Thread Steven D'Aprano
On Fri, 20 Nov 2015 02:42 am, Ian Kelly wrote: > On Thu, Nov 19, 2015 at 5:45 AM, Steven D'Aprano > wrote: >> But if you want the default value to be evaluated exactly once, and once >> only, there is no real alternative to early binding. You could use a >> global variable, of course, but that is

Re: What is a function parameter =[] for?

2015-11-21 Thread Steven D'Aprano
On Fri, 20 Nov 2015 10:59 pm, BartC wrote: > On 20/11/2015 01:05, Steven D'Aprano wrote: >> Here's another use for function defaults, as static storage: [...] >> This is a quick and easy way to memoise a function which would otherwise >> be horribly slow. And it only works because _memo is bound

[RELASE] Python 2.7.11 release candidate 1

2015-11-21 Thread Benjamin Peterson
Greetings, It is my duty and honor to announce the immediate availability of Python 2.7.11 release candidate 1. Python 2.7.11 will be another bug fix release for the 2.7.x series. Downloads are at: https://www.python.org/downloads/release/python-2711rc1/ Please test the candidate and report

Re: anyone tell me why my program will not run?

2015-11-21 Thread Larry Hudson via Python-list
On 11/20/2015 07:30 PM, Dylan Riley wrote: i am learning python and was tasked with making a program that flips a coin 100 times and then tells you the number of heads and tails. I have done so coming up with this piece of work but it doesnt run can anyone help me out? #This is credited to dy

Re: Comparators

2015-11-21 Thread Chris Angelico
On Sun, Nov 22, 2015 at 9:49 AM, Cai Gengyang wrote: > Hmm .. I am a slow learner and have poor memory. Sometimes when I see a new > programming operator, I have to type it out so that I can remember it and let > it sink into my brain > I recommend creating a text file of notes. Every time you

Re: Comparators

2015-11-21 Thread Cai Gengyang
Hmm .. I am a slow learner and have poor memory. Sometimes when I see a new programming operator, I have to type it out so that I can remember it and let it sink into my brain On Sunday, November 22, 2015 at 6:24:28 AM UTC+8, Jon Ribbens wrote: > On 2015-11-21, Cai Gengyang wrote: > > Comparat

Re: Comparators

2015-11-21 Thread Jon Ribbens
On 2015-11-21, Cai Gengyang wrote: > Comparators, interesting ... > booltwo = (10 + 18) == 3**17 booltwo > False What's interesting about that? -- https://mail.python.org/mailman/listinfo/python-list

Comparators

2015-11-21 Thread Cai Gengyang
Comparators, interesting ... >>> booltwo = (10 + 18) == 3**17 >>> booltwo False >>> boolone = (50 - 35) > 35 >>> boolone False >>> booltwo = (65 - 35) > 15 >>> booltwo True >>> boolalpha = 3 < 6 >>> boolalpha True >>> boolbeta = 100 == 10*30 >>> boolbeta False >>> -- https://mail.python.org/mail

Re: need help understanding a python program

2015-11-21 Thread Lee Bradley
On Monday, November 2, 2015 at 1:45:58 PM UTC-5, Ben Finney wrote: > Lee Bradley writes: > > > http://pastebin.com/ndDYjYe1 > > We much prefer to discuss code in the context of plain text messages > right here, because this forum is archived longer than the expected > lifetime of content hosted

Re: using re.split function

2015-11-21 Thread MRAB
On 2015-11-21 18:49, david burstein wrote: im pretty new in python and i didnt get how to use the re.split function. for example if i have a string and i want to split it by two conditions: first one splitting when " [ " appears second one when "]" appears re.split(r" \[ |\]", string) You need

using re.split function

2015-11-21 Thread david burstein
im pretty new in python and i didnt get how to use the re.split function. for example if i have a string and i want to split it by two conditions: first one splitting when " [ " appears second one when "]" appears -- https://mail.python.org/mailman/listinfo/python-list

Re: anyone tell me why my program will not run?

2015-11-21 Thread Pavel Volkov
On суббота, 21 ноября 2015 г. 6:30:02 MSK, Dylan Riley wrote: Also some more notes: heads = int("1") tails = int("2") Why use this strange initialization? The usual way: heads = 1 tails = 2 gives the same result. while flips != 0: flips -= 1 There's no need to use while and flips vari

Re: anyone tell me why my program will not run?

2015-11-21 Thread Pavel Volkov
On суббота, 21 ноября 2015 г. 6:30:02 MSK, Dylan Riley wrote: i am learning python and was tasked with making a program that flips a coin 100 times and then tells you the number of heads and tails. First, you have a syntax error: if result = heads: should be: if result == heads: Second, ther

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

2015-11-21 Thread Chris Angelico
On Sun, Nov 22, 2015 at 2:01 AM, Ian Kelly wrote: >> and then the decorator could wrap the function. I'm not entirely sure >> I could implement it reliably, but even leaving that aside, having to >> put "lambda:" in front of everything is pretty ugly. > > Note that "lambda: []" can also be spelled

Re: Problem to read from array

2015-11-21 Thread Nathan Hilterbrand
On 11/21/2015 10:26 AM, BartC wrote: On 21/11/2015 10:41, vostrus...@gmail.com wrote: Hi, I have a file with one parameter per line: a1 b1 c1 a2 b2 c2 a3 b3 c3 ... The parameters are lines of characters (not numbers) I need to load it to 2D array for further manipulations. So far I managed to

Re: Problem to read from array

2015-11-21 Thread BartC
On 21/11/2015 10:41, vostrus...@gmail.com wrote: Hi, I have a file with one parameter per line: a1 b1 c1 a2 b2 c2 a3 b3 c3 ... The parameters are lines of characters (not numbers) I need to load it to 2D array for further manipulations. So far I managed to upload this file into 1D array: Parame

Re: Problem to read from array

2015-11-21 Thread Laura Creighton
In a message of Sat, 21 Nov 2015 15:22:55 +0100, Laura Creighton writes: >At this point you might get a bit frustrated. Python is happily telling >you that you don't have a newarray[0][0] which is hardly news to you who >was trying to initialise the thing. My bad. I was thinking about 2 dimentio

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

2015-11-21 Thread Ian Kelly
On Sat, Nov 21, 2015 at 1:46 AM, Chris Angelico wrote: > On Sat, Nov 21, 2015 at 7:38 PM, Todd wrote: >> Rather than a dedicated syntax, might this be something that could be >> handled by a built-in decorator? >> >> Maybe something like: >> >> @late_binding >> def myfunc(x, y=[]): > > No, it can

Re: Problem to read from array

2015-11-21 Thread Laura Creighton
In Python we don't write while loops that often. instead we do: for i in range(NumberOfColumns): for j in range(NumberOfRows): do_something() But for the particular case that you are after, constructing lists, we have something even neater -- list comprehensions. So you might write:

Re: *= operator

2015-11-21 Thread Cai Gengyang
>>> bill = 100 >>> bill *= 1.08 >>> bill 108.0 >>> On Saturday, November 21, 2015 at 9:47:29 PM UTC+8, Frank Millman wrote: > "Cai Gengyang" wrote in message > news:a76b1b5b-4321-41bb-aeca-0dac78775...@googlegroups.com... > > > This is a piece of code that calculates tax and tip : > > > > d

Re: *= operator

2015-11-21 Thread Joel Goldstick
On Sat, Nov 21, 2015 at 8:39 AM, Steven D'Aprano wrote: > On Sun, 22 Nov 2015 12:20 am, Cai Gengyang wrote: > > > Does bill *= 1.08 mean bill = bill * 1.15 ? > > No. It means `bill = bill * 1.08`, not 1.15. > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > Other

Re: *= operator

2015-11-21 Thread Frank Millman
"Cai Gengyang" wrote in message news:a76b1b5b-4321-41bb-aeca-0dac78775...@googlegroups.com... This is a piece of code that calculates tax and tip : def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return bill def tip(bill): "

Re: *= operator

2015-11-21 Thread Steven D'Aprano
On Sun, 22 Nov 2015 12:20 am, Cai Gengyang wrote: > Does bill *= 1.08 mean bill = bill * 1.15 ? No. It means `bill = bill * 1.08`, not 1.15. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: *= operator

2015-11-21 Thread BartC
On 21/11/2015 13:20, Cai Gengyang wrote: This is a piece of code that calculates tax and tip : def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return bill def tip(bill): """Adds 15% tip to a restaurant bill.""" bill *

*= operator

2015-11-21 Thread Cai Gengyang
This is a piece of code that calculates tax and tip : def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return bill def tip(bill): """Adds 15% tip to a restaurant bill.""" bill *= 1.15 print "With tip: %f" % bill return

Re: Problem to read from array

2015-11-21 Thread Peter Otten
vostrus...@gmail.com wrote: > Hi, > I have a file with one parameter per line: > a1 > b1 > c1 > a2 > b2 > c2 > a3 > b3 > c3 > ... > The parameters are lines of characters (not numbers) > > I need to load it to 2D array for further manipulations. > So far I managed to upload this file into 1D arra

Problem to read from array

2015-11-21 Thread vostrushka
Hi, I have a file with one parameter per line: a1 b1 c1 a2 b2 c2 a3 b3 c3 ... The parameters are lines of characters (not numbers) I need to load it to 2D array for further manipulations. So far I managed to upload this file into 1D array: ParametersRaw = [] with open(file1) as fh: Parameters

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

2015-11-21 Thread Chris Angelico
On Sat, Nov 21, 2015 at 7:38 PM, Todd wrote: > Rather than a dedicated syntax, might this be something that could be > handled by a built-in decorator? > > Maybe something like: > > @late_binding > def myfunc(x, y=[]): No, it can't; by the time the decorator runs, the expression has already been

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

2015-11-21 Thread Todd
On Nov 19, 2015 20:48, "Chris Angelico" wrote: > > On Fri, Nov 20, 2015 at 5:42 AM, Ian Kelly wrote: > > BartC on the other hand is just complaining about an aspect of Python > > that is legitimately controversial. > > IMO it's controversial mainly because there's an easy and obvious > syntax for