On Thu, Dec 20, 2018 at 10:47:44PM +0100, Aine Gormley wrote:
> Hello, could somebody take a quick look at my code? I am unsure why I am
> getting a loop error?
That's hard to do if you don't show us the code :-)
Please COPY AND PASTE (don't try to retype it from memory) the MINIMUM
amount of c
Greetings Aine!
On Thu, Dec 20, 2018 at 6:57 PM Aine Gormley wrote:
>
> Hello, could somebody take a quick look at my code? I am unsure why I am
> getting a loop error?
This is a plain text only list that does not (typically) allow file
attachments. So I do not see any code. So if you wish for
Hello, could somebody take a quick look at my code? I am unsure why I am
getting a loop error?
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
On 02/08/17 20:53, Borisco Bizaro wrote:
> I try this using loop but could not stop by pressing a key and could not
> give total price please help me
It would help if you showed us the code you wrote with the loop.
Its difficult to guess what you did wrong when we can't see it.
> print"\n welcome
On Mon, Jun 13, 2016 at 6:28 PM Alan Gauld via Tutor
wrote:
> On 13/06/16 08:46, Ek Esawi wrote:
> > Here is a beginner code that might work for you. Best of luck. EK
> >
> > b=[12, 20, 35]
> >
> > for i in range(len(b)):
> > if i==0:
> > c=0
> > else:
> > c=b[i-1]
OPS! This code now produces desired results. I suppose that this works for
smaller blocks. For larger blocks, it might be cumbersome. EK
b=[12, 20, 35]
for i in range(len(b)):
if i==0:
c=0
elif i==2:
c=24
else:
c=b[i-1]
for j in range(c, b[i]):
On 13/06/16 08:46, Ek Esawi wrote:
> Here is a beginner code that might work for you. Best of luck. EK
>
> b=[12, 20, 35]
>
> for i in range(len(b)):
> if i==0:
> c=0
> else:
> c=b[i-1]
> for j in range(c, b[i]):
> print(i+1,j+1)
The problem here is
On Mon, Jun 13, 2016 at 1:33 PM Ek Esawi wrote:
> Here is a beginner code that might work for you. Best of luck. EK
>
> b=[12, 20, 35]
>
> for i in range(len(b)):
> if i==0:
> c=0
> else:
> c=b[i-1]
> for j in range(c, b[i]):
> print(i+1,j+1)
>
If
Here is a beginner code that might work for you. Best of luck. EK
b=[12, 20, 35]
for i in range(len(b)):
if i==0:
c=0
else:
c=b[i-1]
for j in range(c, b[i]):
print(i+1,j+1)
___
Tutor maillist - Tutor@pyth
On 10Jun2016 22:41, Jignesh Sutar wrote:
Is there a better way to code the below than to specify blocks as I have.
Ideally I'd like to specify blocks simply as *blocks=(12,20,35)*
blocks=[(1,12), (13,20), (25,35)]
for i,j in enumerate(blocks):
for x in xrange(blocks[i][0],blocks[i][1]+1):
Sorry, to be a little bit more descriptive. I'd like to loop from 1 to 35
but within this loop there are divisions which I need to prefix that
particular division number.
My output would look like this:
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 2
Is there a better way to code the below than to specify blocks as I have.
Ideally I'd like to specify blocks simply as *blocks=(12,20,35)*
blocks=[(1,12), (13,20), (25,35)]
for i,j in enumerate(blocks):
for x in xrange(blocks[i][0],blocks[i][1]+1):
print i+1, x
Thanks in advance.
Jig
On 10/06/16 23:43, Jignesh Sutar wrote:
> Is there a better way to code the below than to specify blocks as I have.
> Ideally I'd like to specify blocks simply as *blocks=(12,20,35)*
>
> blocks=[(1,12), (13,20), (25,35)]
> for i,j in enumerate(blocks):
> for x in xrange(blocks[i][0],blocks[i][
Is there a better way to code the below than to specify blocks as I have.
Ideally I'd like to specify blocks simply as *blocks=(12,20,35)*
blocks=[(1,12), (13,20), (25,35)]
for i,j in enumerate(blocks):
for x in xrange(blocks[i][0],blocks[i][1]+1):
print i+1, x
Thanks in advance.
Jig
This is pretty cool, Thank you for explaining! I liked the second solution.
Thank you.
On Sunday, July 5, 2015 2:10 AM, Steven D'Aprano
wrote:
Hi Nym, sorry your code's formatting is broken again. I've tried my best
to fix it below:
On Fri, Jul 03, 2015 at 09:04:10PM +, Nym
Hi Nym, sorry your code's formatting is broken again. I've tried my best
to fix it below:
On Fri, Jul 03, 2015 at 09:04:10PM +, Nym City via Tutor wrote:
> Thank to very much for replying. The second solution that you proposed
> worked perfectly:
>
> import csv
> domains = open('top500doma
Thank to very much for replying. The second solution that you proposed worked
perfectly:
import csvdomains = open('top500domains.csv')domainsReader =
csv.reader(domains)domains = ["https://www."; + row[1] for row in
domainsReader]for domain in domains: print(domain) The above solution is
p
On Tue, Jun 30, 2015 at 01:05:13AM +, Nym City wrote:
> Hello all,
> Thank you for your time and tips. The reason why I decided to create a
> loop is because the output is cleaner and did not require any
> formatting. However, based on what I have learned from all of your
> responses, that i
Hello all,
Thank you for your time and tips. The reason why I decided to create a loop is
because the output is cleaner and did not require any formatting. However,
based on what I have learned from all of your responses, that is not going to
work with what I am trying to do.
Here is the updated
Hi Nym, and welcome,
On Sun, Jun 28, 2015 at 07:32:40PM +, Nym City via Tutor wrote:
[...]
> for domain in domainLists:
> something = ("www." + str(domain))
> print(something)
>
> My program reads in a CSV file that has 500 list of domains. However,
> when I save the output of my loop
On 28/06/2015 20:32, Nym City via Tutor wrote:
Hello,
I am working on my second program and its a two part progam that I want to
design However, i am not sure what silly mistake I am making on the first part:
Here is my code:
| 2
3
4
5
6
7 | import csv
domains = open('top500domains.csv')
domain
On 28/06/15 20:32, Nym City via Tutor wrote:
import csv
domains = open('top500domains.csv')
domainsReader = csv.reader(domains)
domainLists = list(domainsReader)
for domain in domainLists:
something = ("www." + str(domain))
You overwrite something each time round the loop.
print(somethi
Hello,
I am working on my second program and its a two part progam that I want to
design However, i am not sure what silly mistake I am making on the first part:
Here is my code:
| 2
3
4
5
6
7 | import csv
domains = open('top500domains.csv')
domainsReader = csv.reader(domains)
domainLists = list(
baidusandy Wrote in message:
[invisible message not copied here]
By posting in html, you managed to pick black on black text. I
literally could see none of your message except the boilerplate.
Please tell your email program to use text mode.
--
DaveA
_
On 22/04/14 17:13, baidusandy wrote:
I'm a newbie to Python. I want to make python useful to my work, to
write a script for get some data out. But there are some setbacks. I
really needs your help. Please, help me.
Its too late for me to study your code properly but here are
a few immediate obs
I'm a newbie to Python. I want to make python useful to my work, to write a
script for get some data out. But there are some setbacks. I really needs your
help. Please, help me.
---the first one--
for x in range(1,a):
tem=open('results\\temp'+str(x))
tem.seek(0)
i_line=tem.
d
>Sent: Wednesday, 19 March 2014, 22:30
>Subject: Re: [Tutor] loop through hours to calc max and plot
>
>
>
>Could you please give an example of how to put these into a loop in a function
>and create the matching naming conventions?
>
>
>
>
>On Thu, Mar 20, 2014 at 8
On 19/03/14 05:12, questions anon wrote:
I have monthly netcdf files containing hourly temperature data.
I would like to loop through all of the hours and calculate the max for
each hour (00 - 23) and then make a plot.
Its hard to give specific help since I don't know the file format
and most
Hi All,
I have monthly netcdf files containing hourly temperature data.
I would like to loop through all of the hours and calculate the max for
each hour (00 - 23) and then make a plot.
I have found a way for this to work for a couple of the hours (see below)
but it requires a lot of set up to do e
On 03/13/2014 04:42 PM, Dave Angel wrote:
spir Wrote in message:
On 03/13/2014 12:40 AM, Danny Yoo wrote:
The context is the beginning of the thread:
https://mail.python.org/pipermail/tutor/2014-March/100543.html
with the loop:
###
while health != 0:
...
###
The point, and
OK, thank you. I knew the loop was infinite but usuyally when I did
infinite loops before, I had them print out a message, so it was obvious.
Thanks for the clarification.
On Thu, Mar 13, 2014 at 9:38 AM, spir wrote:
> On 03/13/2014 12:40 AM, Danny Yoo wrote:
>
>> The context is the beginning o
spir Wrote in message:
> On 03/13/2014 12:40 AM, Danny Yoo wrote:
>> The context is the beginning of the thread:
>>
>> https://mail.python.org/pipermail/tutor/2014-March/100543.html
>>
>> with the loop:
>>
>>
>> ###
>> while health != 0:
>> ...
>> ###
>
> The point, and reason why this
On 03/13/2014 12:40 AM, Danny Yoo wrote:
The context is the beginning of the thread:
https://mail.python.org/pipermail/tutor/2014-March/100543.html
with the loop:
###
while health != 0:
...
###
The point, and reason why this loop was (potentially) infinite, is that the
condition
The context is the beginning of the thread:
https://mail.python.org/pipermail/tutor/2014-March/100543.html
with the loop:
###
while health != 0:
...
###
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
htt
On 12/03/2014 23:18, Danny Yoo wrote:
This particular loop condition looks very suspicious. I would look at
it more closely. When is it false? When is it true?
Context please Danny, we're not all mind readers and we don't all have
photographic memories :)
--
My fellow Pythonistas, ask not
This particular loop condition looks very suspicious. I would look at
it more closely. When is it false? When is it true?
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tu
On 11/03/14 13:53, Yanni Phone wrote:
health = 10
trolls = 0
damage = 3
while health != 0:
trolls += 1
health -= damage
This seems simple enough. (This is an example of a non-terminating loop,
by the way, so it is not suppose to work correctly.)
My problem is that when I enter this
Hello all,
I was following along in a book called 'Python Programming for the Absolute
Beginner' by Michael Dawson and I ran into an odd problem with a loop.
Dawson has the following code in his book:
health = 10
trolls = 0
damage = 3
while health != 0:
trolls += 1
health -= damage
This s
On Mon, Dec 2, 2013 at 4:49 PM, eryksun wrote:
> On Mon, Dec 2, 2013 at 1:28 AM, Amit Saha wrote:
>> Indeed, that's a good point. Surprisingly, C does it just fine:
>>
>> # include
>>
>> int main(int argc, char **argv)
>> {
>> float x = 0.0;
>> while(x<1)
>> {
>> x += 0.1;
>>
On 02/12/2013 12:27, Dave Angel wrote:
On Mon, 2 Dec 2013 16:28:38 +1000, Amit Saha wrote:
Indeed, that's a good point. Surprisingly, C does it just fine:
# include
int main(int argc, char **argv)
{
float x = 0.0;
while(x<1)
{
x += 0.1;
printf("%f\n", x);
}
On Mon, 2 Dec 2013 22:57:30 +1000, Amit Saha
wrote:
You missed the fact that I am printing the value of x *after*
incrementing it.
You're quite right, sorry. I'm too accustomed to the usual c idiom,
which would increment the value at the end of the loop.
--
DaveA
On Mon, Dec 2, 2013 at 10:27 PM, Dave Angel wrote:
> On Mon, 2 Dec 2013 16:28:38 +1000, Amit Saha wrote:
>>
>> Indeed, that's a good point. Surprisingly, C does it just fine:
>
>
>
>> # include
>
>
>
>> int main(int argc, char **argv)
>> {
>> float x = 0.0;
>> while(x<1)
>> {
>> x
On Mon, 2 Dec 2013 16:28:38 +1000, Amit Saha
wrote:
Indeed, that's a good point. Surprisingly, C does it just fine:
# include
int main(int argc, char **argv)
{
float x = 0.0;
while(x<1)
{
x += 0.1;
printf("%f\n", x);
}
return 0;
}
gives the following ou
On Mon, Dec 02, 2013 at 04:28:38PM +1000, Amit Saha wrote:
> On Sun, Dec 1, 2013 at 7:26 PM, Steven D'Aprano wrote:
> > Such floating point loops are tricky to get right, thanks to rounding of
> > floats. Observe:
> >
> > py> x = 0.0
> > py> while x < 1.0:
> > ... x += 0.1
> > ...
> > py> x =
On Mon, Dec 2, 2013 at 1:28 AM, Amit Saha wrote:
> Indeed, that's a good point. Surprisingly, C does it just fine:
>
> # include
>
> int main(int argc, char **argv)
> {
> float x = 0.0;
> while(x<1)
> {
> x += 0.1;
> printf("%f\n", x);
> }
>
> return 0;
> }
Python uses
On Mon, Dec 2, 2013 at 4:36 PM, Asokan Pichai wrote:
> On Mon, Dec 2, 2013 at 11:58 AM, Amit Saha wrote:
>>
>> On Sun, Dec 1, 2013 at 7:26 PM, Steven D'Aprano
>> wrote:
>> > On Sun, Dec 01, 2013 at 07:03:15PM +1000, Amit Saha wrote:
>> >> Hello,
>> >>
>> >> Much to my disbelief, I realized I had
On Sun, Dec 1, 2013 at 7:47 PM, spir wrote:
> On 12/01/2013 10:03 AM, Amit Saha wrote:
>>
>> Hello,
>>
>> Much to my disbelief, I realized I hadn't written a program in Python
>> as far as I can recall which required me to do something like this, in
>> psuedocode:
>>
>> x = 0.1
>>
>> for i = 0 to
On Sun, Dec 1, 2013 at 7:14 PM, Dominik George wrote:
> Hi,
>
>> - Do not create a list of the floating point values as i=[0.01, 0.02,
>> 0.03..] - either like that or by using a suitable mathematical formula
>> combined with a list comprehension
>
> You could simply write your own version of xran
On Sun, Dec 1, 2013 at 7:26 PM, Steven D'Aprano wrote:
> On Sun, Dec 01, 2013 at 07:03:15PM +1000, Amit Saha wrote:
>> Hello,
>>
>> Much to my disbelief, I realized I hadn't written a program in Python
>> as far as I can recall which required me to do something like this, in
>> psuedocode:
>>
>> x
On 12/01/2013 10:03 AM, Amit Saha wrote:
Hello,
Much to my disbelief, I realized I hadn't written a program in Python
as far as I can recall which required me to do something like this, in
psuedocode:
x = 0.1
for i = 0 to x step 0.01
# do something with i
end i
Simply stated, I want to start
On 01/12/2013 09:14, Dominik George wrote:
Hi,
- Do not create a list of the floating point values as i=[0.01, 0.02,
0.03..] - either like that or by using a suitable mathematical formula
combined with a list comprehension
You could simply write your own version of xrange that does it, as a
g
On Sun, Dec 01, 2013 at 07:03:15PM +1000, Amit Saha wrote:
> Hello,
>
> Much to my disbelief, I realized I hadn't written a program in Python
> as far as I can recall which required me to do something like this, in
> psuedocode:
>
> x = 0.1
>
> for i = 0 to x step 0.01
> # do something with i
>
Hi,
> - Do not create a list of the floating point values as i=[0.01, 0.02,
> 0.03..] - either like that or by using a suitable mathematical formula
> combined with a list comprehension
You could simply write your own version of xrange that does it, as a
generator:
def xrange_f(start, stop, st
Hello,
Much to my disbelief, I realized I hadn't written a program in Python
as far as I can recall which required me to do something like this, in
psuedocode:
x = 0.1
for i = 0 to x step 0.01
# do something with i
end i
Simply stated, I want to start from say a value, 0 and go upto 0.1 in
incr
On 17/11/13 01:00, Byron Ruffin wrote:
> When this is run it appears that determineMonthsTilSaved is
> running twice before the loop ends. It is supposed to run
> until saved than goal, but look at the output.
You haven't sent the output, just the code...
> It runs again even after saved goal.
def main():
goal, apr, deposit = getSavingsDetails()
determineMonthsTilSaved( goal, apr, deposit )
months = determineMonthsTilSaved(goal, apr, deposit)
summarize( months )
def getSavingsDetails():
"""
goal = float( input( "Principal sought? $" ) )
apr = float( input(
Ajin Abraham wrote:
> Hi,
>I am using a python snippet that will send some data after the data
> length reaches a particular length. So it is supposed to loop and
> periodically sends the data to an email. i am using smtplib to send
> mail. i will attach the code snippet.
>
> def email():
>
Hi,
I am using a python snippet that will send some data after the data
length reaches a particular length. So it is supposed to loop and
periodically sends the data to an email. i am using smtplib to send
mail. i will attach the code snippet.
def email():
global data
if len(data)>50:
On 06/04/13 23:00, Soliman, Yasmin wrote:
I have two questions on these simple programs:
1st why does this loop keep repeating after I enter 'Quit'?
import calendar
m = raw_input(“Enter a year: “)
while m != “Quit”:
if calendar.isleap(int(m)):
print “%d is a leap year” % (int(m))
else:
On 07/04/13 08:00, Soliman, Yasmin wrote:
I have two questions on these simple programs:
1st why does this loop keep repeating after I enter 'Quit'?
The code you give below is not valid Python code. Please copy and paste *actual* the code
you use, do not retype it from memory. I know that it
On 06/04/2013 23:00, Soliman, Yasmin wrote:
I have two questions on these simple programs:
1st why does this loop keep repeating after I enter 'Quit'?
import calendar
m = raw_input(“Enter a year: “)
while m != “Quit”:
if calendar.isleap(int(m)):
print “%d is a leap year” % (int(m))
else:
On 04/06/2013 06:00 PM, Soliman, Yasmin wrote:
I have two questions on these simple programs:
>
> 1st why does this loop keep repeating after I enter 'Quit'?
>
> import calendar
> m = raw_input(“Enter a year: “)
> while m != “Quit”:
> if calendar.isleap(int(m)):
> print “%d is a leap year” %
I have two questions on these simple programs:
1st why does this loop keep repeating after I enter 'Quit'?
import calendar
m = raw_input(“Enter a year: “)
while m != “Quit”:
if calendar.isleap(int(m)):
print “%d is a leap year” % (int(m))
else:
print “%d is not a leap year” % (int(m))
2n
On 16/03/2013 04:08, Vincent Balmori wrote:
I am trying to loop a simple exception. I tried to put a while loop, but
I keep getting syntax issues. I also tried to alternatively use
something on the lines of "while number != int" also with no avail.
Please help us to help you. What did your whi
On 16 March 2013 05:08, Vincent Balmori wrote:
> I am trying to loop a simple exception. I tried to put a while loop, but I
> keep getting syntax issues. I also tried to alternatively use something on
> the lines of "while number != int" also with no avail.
It would help if you:
a) didn't send HTM
I am trying to loop a simple exception. I tried to put a while loop, but I keep
getting syntax issues. I also tried to alternatively use something on the lines
of "while number != int" also with no avail.
def main():
print("\t\tWelcome to Blackjack!\n")
names = []
try:
On 05/29/2012 08:46 PM, Joseph Rishe wrote:
> #Operating System - Mac OS X 10.6.8
> #Python Version - Python 2.6.6
>
>
>
> ##Goal: I am creating a program to calculate credit card payments.
> ## The user should be able to put in a credit card balance and
> interest
> ## rate, and the p
#Operating System - Mac OS X 10.6.8
#Python Version - Python 2.6.6
##Goal: I am creating a program to calculate credit card payments.
## The user should be able to put in a credit card balance and
interest
## rate, and the program will tell them what monthly payment will
allow
##
Surya K wrote:
I am on windows. So, as msvcrt is for windows, I wonder if there
is any module that works for both,
http://code.activestate.com/recipes/577977
--
Steven
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription opt
On 2012/01/30 07:20 AM, Surya K wrote:
I want to run code until a "enter" is pressed. Well, it shouldn't wait
for the user to enter "enter"
This is my code:
import msvcrt
chr = 0
while chr != 'q':
print "my code",
if msvcrt.kbhit():
chr = msvcrt.getch()
This isn't workin
On 30/01/12 05:20, Surya K wrote:
I want to run code until a "enter" is pressed. Well, it shouldn't wait
for the user to enter "enter"
This is my code:
import msvcrt
chr = 0
while chr != 'q':
print "my code",
if msvcrt.kbhit():
chr = msvcrt.getch()
You shouldn't need the kbhit test.
Try jus
Surya K wrote:
> I want to run code until a "enter" is pressed. Well, it shouldn't wait for
> the user to enter "enter" This is my code:
This is what it looks like over here:
> import msvcrtchr = 0while chr != 'q': print "my code", if
> msvcrt.kbhit(): chr = msvcrt.getch()
Th
I want to run code until a "enter" is pressed. Well, it shouldn't wait for the
user to enter "enter"
This is my code:
import msvcrtchr = 0while chr != 'q': print "my code", if
msvcrt.kbhit(): chr = msvcrt.getch()
This isn't working the way I wanted. When ever I press enter, the
"Vincent Balmori" wrote
you the number of heads and tails." Right now I am
having trouble connecting the random.randint function
into the loop.
Break the problem statement down.
You have correctly worked out that randint(1,2) will equate
to tossing the coin.
You want to do that 100 times
Vincent,
You will need to move the line that flips the coin:
coin = random.randint(1,2)
and the if/else logic *inside* the loop so it will be repeated as many
times as needed.
I'm not sure what you want to do with the input() inside the loop. Remove this.
Alex
2011/6/4 Vincent Balmori :
> H
Hello. Right now I am learning the python language through Python Programming
for the Absolute Beginner 3rd Edition. I am having trouble with one question in
Ch. 3 #2, which says "Write a program that flips a coin 100 times and then
tells
you the number of heads and tails." Right now I am havin
hi,
thanks for the feedback, it is much appreciated.
On Fri, May 21, 2010 at 7:54 PM, bob gailer wrote:
> Also note that the database function creates a local variable "database" but
> does nothing with it.
> When the function terminates that variable is lost.
> Did you intend to return it?
yes,
Also note that the database function creates a local variable "database"
but does nothing with it.
When the function terminates that variable is lost.
Did you intend to return it?
Also it is not good practice to use the same name for a function and a
variable.
--
Bob Gailer
919-636-4239
Chapel
On 5/21/2010 5:35 AM, Norman Khine wrote:
hello,
i have this script, but i am stuck at the loop, if the user types an
incorrect database id:
http://paste.lisp.org/+25D3
how would i write the exception correctly?
Which line of code could raise the ValueError exception?
That line should be
hello,
i have this script, but i am stuck at the loop, if the user types an
incorrect database id:
http://paste.lisp.org/+25D3
how would i write the exception correctly?
norman
--
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
__
thanks Steve, this response came handy.
I would have to take this home and read. if i encounter difficulties,
I'd get back to the house.
I'm grateful.
If I get more explanations though, it would be great.
Regards,
On 5/18/10, Steve Willoughby wrote:
> I'm changing the subject line because this is
I'm changing the subject line because this is going into a different topic.
On Tue, May 18, 2010 at 05:39:50PM +0100, Dipo Elegbede wrote:
> A LITTLE EXPLANATIONS ON CONTINUE WOULD BE APPRECIATED TOO.
> in a recap, i would appreciate any brief explanation on
> 1. break
> 2. continue
> 3. while loo
Dave Angel, 17.04.2010 10:47:
Alan Gauld wrote:
"Lie Ryan" wrote
A friend of mine suggested me to do the next experiment in python
and Java.
It's a simple program to sum all the numbers from 0 to 10.
result = i = 0
while i < 10:
result += i
i += 1
print result
Are you sure
Alan Gauld wrote:
"Lie Ryan" wrote
A friend of mine suggested me to do the next experiment in python
and Java.
It's a simple program to sum all the numbers from 0 to 10.
result = i = 0
while i < 10:
result += i
i += 1
print result
Are you sure you're not causing Ja
Hi.
Thanks for everyone answers. It's true, hehe, it's not a benchmark
or anything like that. I hadn't taken into account compiler
optimizations, but I have learnt a lot in this thread.
About the Java code, Bigints are used.
ark
___
Tutor maillist -
"Lie Ryan" wrote
A friend of mine suggested me to do the next experiment in python and Java.
It's a simple program to sum all the numbers from 0 to 10.
result = i = 0
while i < 10:
result += i
i += 1
print result
Are you sure you're not causing Java to overflow here?
> result = sum(range(10))
>
> although it still took 10 minutes on my PC.
Did you mean to say "minutes" or rather "seconds" here? And did you
really mean to use "range" or rather "xrange" (or "range" in Py3)?
Yes, minutes and in Python 3.
And on a 2.8GHz 2 core CPU with 2G RAM
su
"Steven D'Aprano" wrote
(We can of course do some fancy math to speed this particular
sum up since the result for any power of ten has a common pattern,
but I wouldn't expect the compiler optimiser to be that clever)
No fancy maths needed,
The sum of 1,2,3,4,...,N is given by a simple for
ALAN GAULD wrote:
The precalculation optimisations are
taking place. If you pass it an argument to use for the upper limit of the
sequence the calculation time shoots up.
I'm still confused about when the addition takes place.
Surely the compiler has to do the addition, so it should
On 04/16/10 16:50, Ark wrote:
> Hi everyone.
> A friend of mine suggested me to do the next experiment in python and Java.
>
> It's a simple program to sum all the numbers from 0 to 10.
>
> result = i = 0
> while i < 10:
> result += i
> i += 1
> print result
>
Are you su
Steven D'Aprano, 16.04.2010 12:00:
On Fri, 16 Apr 2010 06:29:40 pm Alan Gauld wrote:
"Stefan Behnel" wrote
import cython
@cython.locals(result=cython.longlong, i=cython.longlong)
def add():
result = 0
for i in xrange(10):
result += i
On Fri, 16 Apr 2010 06:25:54 pm Stefan Behnel wrote:
> Alan Gauld, 16.04.2010 10:09:
> > Even the built in sum() will be faster than a while loop:
> >
> > result = sum(range(10))
> >
> > although it still took 10 minutes on my PC.
>
> Did you mean to say "minutes" or rather "seconds" here?
On Fri, 16 Apr 2010 06:29:40 pm Alan Gauld wrote:
> "Stefan Behnel" wrote
>
> > import cython
> >
> > @cython.locals(result=cython.longlong, i=cython.longlong)
> > def add():
> > result = 0
> > for i in xrange(10):
> > result += i
> > return
> The precalculation optimisations are
> taking place. If you pass it an argument to use for the upper limit of the
> sequence the calculation time shoots up.
I'm still confused about when the addition takes place.
Surely the compiler has to do the addition, so it should be slower?
I assume
Alan Gauld, 16.04.2010 10:29:
"Stefan Behnel" wrote
import cython
@cython.locals(result=cython.longlong, i=cython.longlong)
def add():
result = 0
for i in xrange(10):
result += i
return result
print add()
This runs in less than half a second on my machine, includin
Dave Angel wrote:
Christian Witts wrote:
Ark wrote:
Hi everyone.
A friend of mine suggested me to do the next experiment in python
and Java.
It's a simple program to sum all the numbers from 0 to 10.
result = i = 0
while i < 10:
result += i
i += 1
print result
The
Alan Gauld wrote:
"Stefan Behnel" wrote
import cython
@cython.locals(result=cython.longlong, i=cython.longlong)
def add():
result = 0
for i in xrange(10):
result += i
return result
print add()
This runs in less than half a second on
Stefan Behnel, 16.04.2010 09:38:
A compiler for a statically compiled language can see that the
above loop yields a constant result, so it can calculate the result in
advance (or at least reduce the loop overhead for the calculation)
instead of generating code for the loop as it stands.
That re
Christian Witts wrote:
Ark wrote:
Hi everyone.
A friend of mine suggested me to do the next experiment in python and
Java.
It's a simple program to sum all the numbers from 0 to 10.
result = i = 0
while i < 10:
result += i
i += 1
print result
The time for this calc
"Stefan Behnel" wrote
import cython
@cython.locals(result=cython.longlong, i=cython.longlong)
def add():
result = 0
for i in xrange(10):
result += i
return result
print add()
This runs in less than half a second on my machine, inclu
1 - 100 of 129 matches
Mail list logo