Re: [Tutor] loop error

2018-12-20 Thread Steven D'Aprano
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

Re: [Tutor] loop error

2018-12-20 Thread boB Stepp
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

[Tutor] loop error

2018-12-20 Thread Aine Gormley
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

[Tutor] Loop problem (was: Re: Tutor Digest, Vol 161, Issue 42)

2017-08-02 Thread Alan Gauld via 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

Re: [Tutor] Loop in pre-defined blocks

2016-06-13 Thread Michael Selik
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]

Re: [Tutor] Loop in pre-defined blocks

2016-06-13 Thread Ek Esawi
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]):

Re: [Tutor] Loop in pre-defined blocks

2016-06-13 Thread Alan Gauld via Tutor
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

Re: [Tutor] Loop in pre-defined blocks

2016-06-13 Thread Michael Selik
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

Re: [Tutor] Loop in pre-defined blocks

2016-06-13 Thread Ek Esawi
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

Re: [Tutor] Loop blocks

2016-06-11 Thread cs
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):

Re: [Tutor] Loop in pre-defined blocks

2016-06-10 Thread Jignesh Sutar
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

[Tutor] Loop blocks

2016-06-10 Thread Jignesh Sutar
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

Re: [Tutor] Loop in pre-defined blocks

2016-06-10 Thread Alan Gauld via Tutor
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][

[Tutor] Loop in pre-defined blocks

2016-06-10 Thread Jignesh Sutar
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

Re: [Tutor] Loop not iterating

2015-07-05 Thread Nym City via Tutor
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

Re: [Tutor] Loop not iterating

2015-07-04 Thread Steven D'Aprano
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

Re: [Tutor] Loop not iterating

2015-07-03 Thread Nym City via Tutor
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

Re: [Tutor] Loop not iterating

2015-06-29 Thread Steven D'Aprano
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

Re: [Tutor] Loop not iterating

2015-06-29 Thread Nym City via Tutor
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

Re: [Tutor] Loop not iterating

2015-06-28 Thread Steven D'Aprano
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

Re: [Tutor] Loop not iterating

2015-06-28 Thread Mark Lawrence
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

Re: [Tutor] Loop not iterating

2015-06-28 Thread Alan Gauld
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

[Tutor] Loop not iterating

2015-06-28 Thread Nym City via Tutor
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(

Re: [Tutor] loop couldn't work well and file couldn't close

2014-04-22 Thread Dave Angel
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 _

Re: [Tutor] loop couldn't work well and file couldn't close

2014-04-22 Thread Alan Gauld
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

[Tutor] loop couldn't work well and file couldn't close

2014-04-22 Thread baidusandy
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.

Re: [Tutor] loop through hours to calc max and plot

2014-03-19 Thread ALAN GAULD
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

Re: [Tutor] loop through hours to calc max and plot

2014-03-19 Thread Alan Gauld
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

[Tutor] loop through hours to calc max and plot

2014-03-18 Thread questions anon
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

Re: [Tutor] Loop Issue

2014-03-14 Thread spir
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

Re: [Tutor] Loop Issue

2014-03-13 Thread Yanni Phone
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

Re: [Tutor] Loop Issue

2014-03-13 Thread Dave Angel
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

Re: [Tutor] Loop Issue

2014-03-13 Thread spir
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

Re: [Tutor] Loop Issue

2014-03-12 Thread Danny Yoo
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

Re: [Tutor] Loop Issue

2014-03-12 Thread Mark Lawrence
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

Re: [Tutor] Loop Issue

2014-03-12 Thread Danny Yoo
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

Re: [Tutor] Loop Issue

2014-03-12 Thread Alan Gauld
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

[Tutor] Loop Issue

2014-03-12 Thread Yanni Phone
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

Re: [Tutor] Loop over floating point values

2013-12-07 Thread Amit Saha
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; >>

Re: [Tutor] Loop over floating point values

2013-12-02 Thread Mark Lawrence
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); }

Re: [Tutor] Loop over floating point values

2013-12-02 Thread Dave Angel
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

Re: [Tutor] Loop over floating point values

2013-12-02 Thread Amit Saha
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

Re: [Tutor] Loop over floating point values

2013-12-02 Thread Dave Angel
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

Re: [Tutor] Loop over floating point values

2013-12-02 Thread Steven D'Aprano
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 =

Re: [Tutor] Loop over floating point values

2013-12-01 Thread eryksun
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread spir
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Mark Lawrence
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

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Steven D'Aprano
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 >

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Dominik George
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

[Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
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

Re: [Tutor] loop running twice?

2013-11-17 Thread Alan Gauld
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.

[Tutor] loop running twice?

2013-11-17 Thread Byron Ruffin
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(

Re: [Tutor] Loop not executing.

2013-04-30 Thread Prasad, Ramit
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(): >

[Tutor] Loop not executing.

2013-04-30 Thread Ajin Abraham
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:

Re: [Tutor] loop questions

2013-04-07 Thread Alan Gauld
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:

Re: [Tutor] loop questions

2013-04-06 Thread Steven D'Aprano
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

Re: [Tutor] loop questions

2013-04-06 Thread Mark Lawrence
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:

Re: [Tutor] loop questions

2013-04-06 Thread Mitya Sirenef
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” %

[Tutor] loop questions

2013-04-06 Thread Soliman, Yasmin
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

Re: [Tutor] Loop Exception Handles

2013-03-15 Thread Mark Lawrence
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

Re: [Tutor] Loop Exception Handles

2013-03-15 Thread Robert Sjoblom
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

[Tutor] Loop Exception Handles

2013-03-15 Thread Vincent Balmori
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:      

Re: [Tutor] Loop Question - Beginner Help (Thanks in Advance)

2012-05-29 Thread Dave Angel
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

[Tutor] Loop Question - Beginner Help (Thanks in Advance)

2012-05-29 Thread Joseph Rishe
#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 ##

Re: [Tutor] loop until a keypress

2012-01-30 Thread Steven D'Aprano
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

Re: [Tutor] loop until a keypress

2012-01-30 Thread Christian Witts
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

Re: [Tutor] loop until a keypress

2012-01-30 Thread Alan Gauld
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

Re: [Tutor] loop until a keypress

2012-01-30 Thread Peter Otten
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

[Tutor] loop until a keypress

2012-01-29 Thread Surya K
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

Re: [Tutor] Loop

2011-06-04 Thread Alan Gauld
"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

Re: [Tutor] Loop

2011-06-04 Thread Alexandre Conrad
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

[Tutor] Loop

2011-06-04 Thread Vincent Balmori
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

Re: [Tutor] loop raw input

2010-05-21 Thread Norman Khine
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,

Re: [Tutor] loop raw input

2010-05-21 Thread bob gailer
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

Re: [Tutor] loop raw input

2010-05-21 Thread bob gailer
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

[Tutor] loop raw input

2010-05-21 Thread Norman Khine
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" ] ) __

Re: [Tutor] Loop basics (was Re: what is wrong with this syntax?)

2010-05-18 Thread Dipo Elegbede
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

[Tutor] Loop basics (was Re: what is wrong with this syntax?)

2010-05-18 Thread Steve Willoughby
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

Re: [Tutor] Loop comparison

2010-04-17 Thread Stefan Behnel
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

Re: [Tutor] Loop comparison

2010-04-17 Thread Dave Angel
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Ark
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 -

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"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?

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
> 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

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"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

Re: [Tutor] Loop comparison

2010-04-16 Thread Dave Angel
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Lie Ryan
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Steven D'Aprano
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?

Re: [Tutor] Loop comparison

2010-04-16 Thread Steven D'Aprano
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

Re: [Tutor] Loop comparison

2010-04-16 Thread ALAN GAULD
> 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

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Christian Witts
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Christian Witts
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Stefan Behnel
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Dave Angel
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

Re: [Tutor] Loop comparison

2010-04-16 Thread Alan Gauld
"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   2   >