Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
On Thursday, June 23, 2016 at 12:17:23 AM UTC-4, Elizabeth Weiss wrote: > CODE #1: > > i=0 > while 1==1: >print(i) >i=i+1 >if i>=5: > print("Breaking") > break > > -- > I understand that i=0 and i will only be printed if 1=1 > The results of this is > 0 > 1 > 2 > 3 > 4 >

Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
gt; > i=i+1 adds 1 to the current value of i, then assigns that value to i. > > You can increment i by whatever you want: > i=i+1 > i=i+2 > i=i+35 > etc. > > > > > > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > >

Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
if i==2: > > print("Skipping 2") > > continue > > if i==5: > > print("Breaking") > > break > >print(i) > > > > -- > > > > Questions: > > 1. what does the word True have to do with an

Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
On Thursday, June 23, 2016 at 12:49:30 AM UTC-4, Lawrence D’Oliveiro wrote: > On Thursday, June 23, 2016 at 4:17:23 PM UTC+12, Elizabeth Weiss wrote: > > > > i=0 > > while 1==1: > >print(i) > >i=i+1 > >if i>=5: > > print("Breaking") > > break > > > > Why is Breaking going to

Re: Break and Continue: While Loops

2016-06-26 Thread Steven D'Aprano
On Sun, 26 Jun 2016 05:32 pm, Lawrence D’Oliveiro wrote: > On Thursday, June 23, 2016 at 11:58:01 PM UTC+12, Jon Ribbens wrote: >> I seem to recall that Java originally insisted that only booleans >> (excluding even Booleans, which are a different thing because of >> course they are) could be chec

Re: Break and Continue: While Loops

2016-06-26 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 11:58:01 PM UTC+12, Jon Ribbens wrote: > I seem to recall that Java originally insisted that only booleans > (excluding even Booleans, which are a different thing because of > course they are) could be checked for truth and it was one of > Java's significant warts. Ja

Re: Break and Continue: While Loops

2016-06-24 Thread Pierre-Alain Dorange
BartC wrote: > But even with ordinary conditionals, False is False, but [False] is > True. And [] is False, while [[]] is True. A class instance is always > True, even when empty. And then "False" is True as well! "Empty" is not "Nothing". To be empty, something must exist first. -- Pierre-Al

Re: Break and Continue: While Loops

2016-06-23 Thread John Gordon
In <639b00e0-7b9d-4ed4-96ad-6afbcd536...@googlegroups.com> Elizabeth Weiss writes: > i=0 > while 1==1: >print(i) >i=i+1 >if i>=5: > print("Breaking") > break > Why is Breaking going to be printed if i only goes up to 4? Your code prints i and THEN adds one to it. So i is

Re: Break and Continue: While Loops

2016-06-23 Thread Chris Angelico
On Fri, Jun 24, 2016 at 1:52 AM, BartC wrote: > On 23/06/2016 12:39, Chris Angelico wrote: >> >> On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >>> >>> Actually pretty much any expression can be used, because Python can >>> interpret almost anything as either True or False. Don't ask for the >>> r

Re: Break and Continue: While Loops

2016-06-23 Thread BartC
On 23/06/2016 12:39, Chris Angelico wrote: On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: Actually pretty much any expression can be used, because Python can interpret almost anything as either True or False. Don't ask for the rules because they can be complicated, but for example, zero is False

Re: Break and Continue: While Loops

2016-06-23 Thread Jon Ribbens
On 2016-06-23, Chris Angelico wrote: > On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >> Actually pretty much any expression can be used, because Python can >> interpret almost anything as either True or False. Don't ask for the rules >> because they can be complicated, but for example, zero is Fa

Re: Break and Continue: While Loops

2016-06-23 Thread Chris Angelico
On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: > Actually pretty much any expression can be used, because Python can > interpret almost anything as either True or False. Don't ask for the rules > because they can be complicated, but for example, zero is False, and any > other number is True. I thin

Re: Break and Continue: While Loops

2016-06-23 Thread BartC
On 23/06/2016 05:17, Elizabeth Weiss wrote: CODE #1: i=0 while True: i=i+1 if i==2: print("Skipping 2") continue if i==5: print("Breaking") break print(i) -- Questions: 2. i=i+1- I never understand this. Why isn't it i=i+2? 3. Do the results not include 2 of

Re: Break and Continue: While Loops

2016-06-23 Thread alister
On Wed, 22 Jun 2016 21:17:03 -0700, Elizabeth Weiss wrote: > CODE #1: > > i=0 while 1==1: >print(i) >i=i+1 if i>=5: > print("Breaking") break > > -- > I understand that i=0 and i will only be printed if 1=1 The results of > this is 0 > 1 > 2 > 3 > 4 > Breaking > > Why is Breaki

Re: Break and Continue: While Loops

2016-06-23 Thread Steven D'Aprano
starts off as 0. But then you increase it by 1 each time around the loop. Can I ask, have you learned about for loops yet? There seems to be a fashion among some teachers and educators to teach while loops before for loops. I think that is a terrible idea, while loops are so much more compli

Re: Break and Continue: While Loops

2016-06-22 Thread Rustom Mody
ing here? > 2. i=i+1- I never understand this. Why isn't it i=i+2? > 3. Do the results not include 2 of 5 because we wrote if i==2 and if i==5? > 4. How is i equal to 2 or 5 if i=0? > > Thanks for all of your help! I suggested in your other post (Subject While Loops) that the

Re: Break and Continue: While Loops

2016-06-22 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 4:17:23 PM UTC+12, Elizabeth Weiss wrote: > > i=0 > while 1==1: >print(i) >i=i+1 >if i>=5: > print("Breaking") > break > > Why is Breaking going to be printed if i only goes up to 4? It does say if > i>=5? Because you incremented i after printi

Break and Continue: While Loops

2016-06-22 Thread Elizabeth Weiss
CODE #1: i=0 while 1==1: print(i) i=i+1 if i>=5: print("Breaking") break -- I understand that i=0 and i will only be printed if 1=1 The results of this is 0 1 2 3 4 Breaking Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this me

Re: while Loops

2016-06-22 Thread John Gordon
In <0cf9a94e-b84c-460d-b03d-edf6a941a...@googlegroups.com> Elizabeth Weiss writes: > Why is one of the results 5 since i=i+1? Should the maximum result > be 4 since 4 +1=5? "while i<=5" means "while i is less than or equal to 5". So the loop will keep going at 5, and only stop when i is 6. -

Re: while Loops

2016-06-22 Thread alister
On Tue, 21 Jun 2016 20:50:24 -0700, Elizabeth Weiss wrote: > i=1 while i<=5: >print(i) >i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 > since 4 +1=5? > > Thanks for your help! check you loop condition while i le

Re: while Loops

2016-06-21 Thread Michael Torrie
On 06/21/2016 09:50 PM, Elizabeth Weiss wrote: > i=1 > while i<=5: >print(i) >i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 since > 4 +1=5? > > Thanks for your help! If you trace the execution through in your m

Re: while Loops

2016-06-21 Thread Ben Finney
Elizabeth Weiss writes: > Why is one of the results 5 since i=i+1? What do you think ‘i = i + 1’ means? (Asking because your idea of what that means may be affecting how you expect the loop to behave.) > Should the maximum result be 4 since 4 +1=5? Try “thinking like the computer”: perform the

Re: while Loops

2016-06-21 Thread Rustom Mody
On Wednesday, June 22, 2016 at 9:20:35 AM UTC+5:30, Elizabeth Weiss wrote: > i=1 > while i<=5: >print(i) >i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 since > 4 +1=5? > Not sure what your question is But I gue

Re: while Loops

2016-06-21 Thread Wildman via Python-list
On Tue, 21 Jun 2016 20:50:24 -0700, Elizabeth Weiss wrote: > i=1 > while i<=5: >print(i) >i=i+1 > > The result is: > 1 > 2 > 3 > 4 > 5 > > Why is one of the results 5 since i=i+1? Should the maximum result be 4 since > 4 +1=5? > > Thanks for your help! The operator '<=' means less th

while Loops

2016-06-21 Thread Elizabeth Weiss
i=1 while i<=5: print(i) i=i+1 The result is: 1 2 3 4 5 Why is one of the results 5 since i=i+1? Should the maximum result be 4 since 4 +1=5? Thanks for your help! -- https://mail.python.org/mailman/listinfo/python-list

Re: I donä't get while-loops

2008-08-02 Thread Tyler Breisacher
You're actually calling the read2() function from within read2(). This is called recursion, and it is *not* what you want in this case, since it unnecessarily fills up your call stack. Remember that a while loop automatically goes back to the top without you having to re-call your function. I w

Re: I donä't get while-loops

2008-08-02 Thread ssecorp
oops, embarrassing, I created the while loop not to use recursion then I still did... -- http://mail.python.org/mailman/listinfo/python-list

Re: I donä't get while-loops

2008-08-02 Thread Larry Bates
ssecorp wrote: in read2 it never quits when I write quit, why? def read(): expr = raw_input("Lisp> ") if expr != "quit": print parse(expr) read() else: print "Good session!" def read2(): expr = "" while expr != "quit": expr = raw_input("Lisp>

Re: I donä't get while-loops

2008-08-02 Thread Stefaan Himpe
def read2(): expr = "" while expr != "quit": expr = raw_input("Lisp> ") print parse(expr) read2() ^ print "Good session!" You shouldn't call read2() inside read2()... just remove that line and retry... Each time you call read2() recursivel

I donä't get while-loops

2008-08-02 Thread ssecorp
in read2 it never quits when I write quit, why? def read(): expr = raw_input("Lisp> ") if expr != "quit": print parse(expr) read() else: print "Good session!" def read2(): expr = "" while expr != "quit": expr = raw_input("Lisp> ") print

Re: while-loops enter the last time after condition is filled?

2008-04-07 Thread [EMAIL PROTECTED]
On 6 avr, 01:53, [EMAIL PROTECTED] wrote: > it seems to me from my results that when i use a while-loop it will > execute once after the condition is met. > > ie the conditions is met the code executes one time more and then > quits. The problem is obviously in your code, but since you failed to p

Re: while-loops enter the last time after condition is filled?

2008-04-06 Thread Sumit
On Apr 6, 4:53 am, [EMAIL PROTECTED] wrote: > it seems to me from my results that when i use a while-loop it will > execute once after the condition is met. Perhaps your condition is wrong. Please provide the code where this occured. -- http://mail.python.org/mailman/listinfo/python-list

Re: while-loops enter the last time after condition is filled?

2008-04-05 Thread John Machin
On Apr 6, 9:53 am, [EMAIL PROTECTED] wrote: > it seems to me from my results that when i use a while-loop it will > execute once after the condition is met. > > ie the conditions is met the code executes one time more and then > quits. The syntax is this: while condition: do_something

Re: while-loops enter the last time after condition is filled?

2008-04-05 Thread Tim Chase
> it seems to me from my results that when i use a while-loop it > will execute once after the condition is met. Nope. > ie the conditions is met the code executes one time more and > then quits. Must be that your conditional is wrong, or your conditions are not updated the way you think they a

while-loops enter the last time after condition is filled?

2008-04-05 Thread skanemupp
it seems to me from my results that when i use a while-loop it will execute once after the condition is met. ie the conditions is met the code executes one time more and then quits. -- http://mail.python.org/mailman/listinfo/python-list

Re: for and while loops

2006-06-28 Thread Bruno Desthuilliers
Bayazee a écrit : > hi > > #Exercise 1 : > s=0 > while 1: > s+=input("Enter a num : ") > if s>=100: > print "The sum is greater than 100 : ",s > break Why do you manually check the condition when the construct is meant to take care of it ? the_sum = 0 while the_sum < 100: try:

Re: for and while loops

2006-06-28 Thread Simon Forman
[EMAIL PROTECTED] wrote: > i was wondering if anyone could point me to some good reading about the > for and while loops > > i am trying to write some programs > "Exercise 1 > > Write a program that continually reads in numbers from the user and > adds them toget

Re: for and while loops

2006-06-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > i was wondering if anyone could point me to some good reading about the > for and while loops There's not much to say. while : will execute as long as is True. for in : will execute for each in . ie : for letter in [&

Re: for and while loops

2006-06-28 Thread Schüle Daniel
[EMAIL PROTECTED] schrieb: > i was wondering if anyone could point me to some good reading about the > for and while loops > > i am trying to write some programs > "Exercise 1 > > Write a program that continually reads in numbers from the user and > adds them toget

Re: for and while loops

2006-06-28 Thread Bayazee
hi #Exercise 1 : s=0 while 1: s+=input("Enter a num : ") if s>=100: print "The sum is greater than 100 : ",s break #Exercise 2 : s=0 for i in range(5): s+=input("Enter num #%d > "%(i+1)) print "The Sum is : " , s -- http://mail.python.org/mailman/listinfo/python-list

Re: for and while loops

2006-06-28 Thread Bayazee
hi #Exercise 1 : s=0 while 1: s+=input("Enter a num : ") if s>=100: print "The sum is greater than 100 : ",s break #Exercise 1 : s=0 for i in range(5): s+=input("Enter num #%d > "%(i+1)) print "The Sum is : " , s -- http://mail.python.org/mailman/listinfo/python-list

for and while loops

2006-06-28 Thread [EMAIL PROTECTED]
i was wondering if anyone could point me to some good reading about the for and while loops i am trying to write some programs "Exercise 1 Write a program that continually reads in numbers from the user and adds them together until the sum reaches 100. Write another program that read