e problem is the real time execution of the program (in class2) requires
an instant check to be performed and that cannot wait until the current
loop instructions finish, and I want is to break out of the outer while
loop if the event is on without further checking any other condition.
for n
dn writes:
[...]
> Further, if you look at the OP's original solution, it only publishes
> the last pair, ie the match, without mention of the list of non-matches.
> Was it perhaps only a means of testing the solution?
It was a means of showing the student that indeed they obtained a match.
If
On 11/09/2021 10:09, dn via Python-list wrote:
The stated requirement is: "I'd like to get the number of times I
tried". Given such: why bother with returning any of the pairs of values?
Indeed, if that's the requirement, then you can do even better, noting
that the probability of getting a
On 2021-09-08 13:07:47 +1200, Greg Ewing wrote:
> On 8/09/21 2:53 am, Grant Edwards wrote:
> >#define IF if (
> >#define THEN ) {
> >#define ELSE } else {
> >#define ENDIF }
>
> I gather that early versions of some of the Unix utilities were
> written by someone who liked using mac
On 11/09/2021 18.03, Chris Angelico wrote:
> On Sat, Sep 11, 2021 at 3:26 PM dn via Python-list
> wrote:
>>
>> On 31/08/2021 01.50, Chris Angelico wrote:
>>> On Mon, Aug 30, 2021 at 11:13 PM David Raymond
>>> wrote:
> def how_many_times():
> x, y = 0, 1
> c = 0
> wh
On Sat, Sep 11, 2021 at 3:26 PM dn via Python-list
wrote:
>
> On 31/08/2021 01.50, Chris Angelico wrote:
> > On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> > wrote:
> >>
> >>> def how_many_times():
> >>> x, y = 0, 1
> >>> c = 0
> >>> while x != y:
> >>> c = c + 1
> >>> x, y = rol
On 31/08/2021 01.50, Chris Angelico wrote:
> On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> wrote:
>>
>>> def how_many_times():
>>> x, y = 0, 1
>>> c = 0
>>> while x != y:
>>> c = c + 1
>>> x, y = roll()
>>> return c, (x, y)
>>
>> Since I haven't seen it used in answers yet, her
On Wed, 8 Sep 2021 16:32:45 - (UTC), Grant Edwards
declaimed the following:
>On 2021-09-08, Dennis Lee Bieber wrote:
>
>> I spent close to 20 years (80s-90s) maintaining the /output/ of such
>> a preprocessor.
>
>Ouch. I hope it paid well. ;)
Only if one ignores the bloody cost of a
On Wed, 8 Sep 2021 14:46:28 - (UTC), Grant Edwards
declaimed the following:
>On 2021-09-08, charles hottel wrote:
>
>> So what do yoy think or feel about a language like RATFOR (Rational
>> FORTRAN) which was implemented as macros? Should they instead have
>> simply adapted themselves to
On 2021-09-08, Dennis Lee Bieber wrote:
> I spent close to 20 years (80s-90s) maintaining the /output/ of such
> a preprocessor.
Ouch. I hope it paid well. ;)
Back when I did a lot of TeX/LaTeX stuff on VMS, I used to make
occasional fixes and add (very minor) features to one of the dvi
handlin
customize Python to a point where it does things in fairly
hidden ways too. There are no promises of purity.
What this particular discussion began with was much lower level and about
various ways of writing a while loop within very basic Python and seems to
be heading away into discussions of other
On Wed, 8 Sep 2021 00:24:44 +0100, Alan Gauld via Python-list
declaimed the following:
>
>That was quite common in C before it became popular(early/mid 80s).
>I've seen Pascal, Algol and Coral macro sets in use.
>You could even download pre-written ones from various
>bulletin boards (remember the
On 2021-09-08, charles hottel wrote:
> So what do yoy think or feel about a language like RATFOR (Rational
> FORTRAN) which was implemented as macros?
The RATFOR implementations I've seen weren't done using macros. It was
a preprocessor, yes. But it generates code for the various structured
sta
On 2021-09-08, charles hottel wrote:
> So what do yoy think or feel about a language like RATFOR (Rational
> FORTRAN) which was implemented as macros? Should they instead have
> simply adapted themselves to FORTRAN?
That's an interesting question. If the langauge is complete,
well-defined, an
7, 2021 9:08 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On 8/09/21 2:53 am, Grant Edwards wrote:
#define IF if (
#define THEN ) {
#define ELSE } else {
#define ENDIF }
...
I gather that early versions of some of the Unix utilities
another object means you over-rode the meaning of
+= for instance.
-Original Message-
From: Python-list On
Behalf Of Richard Damon
Sent: Tuesday, September 7, 2021 10:09 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On 9/7/21 3:51 PM, Avi Gross via
On 9/7/21 3:51 PM, Avi Gross via Python-list wrote:
> and similarly changes any function imported directly
> to also be fully qualified.
One danger with this is that it can actual change the behavior of the
program. Maybe more likely with global objects than functions, but still
an issue.
Remembe
@python.org
Subject: Re: on writing a while loop for rolling two dice
On 8/09/21 2:53 am, Grant Edwards wrote:
>#define IF if (
>#define THEN ) {
>#define ELSE } else {
>#define ENDIF }
>...
I gather that early versions of some of the Unix utilities were written by
so
On 8/09/21 2:53 am, Grant Edwards wrote:
#define IF if (
#define THEN ) {
#define ELSE } else {
#define ENDIF }
...
I gather that early versions of some of the Unix utilities were
written by someone who liked using macros to make C resemble Algol.
I guess you can get away with t
On 07/09/2021 15:53, Grant Edwards wrote:
> I remember engineering manager I worked with about 35 years ago who
> used a set of C macros to try to make his code look as much like BASIC
> as possible:
>
> #define IF if (
> #define THEN ) {
> #define ELSE } else {
> #define ENDIF }
> ...
alister via Python-list
Sent: Tuesday, September 7, 2021 2:58 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On Tue, 07 Sep 2021 14:53:29 +, Grant Edwards wrote:
> On 2021-09-06, Stefan Ram wrote:
>> "Avi Gross" writes:
>&g
On Tue, 7 Sep 2021 16:08:04 +1200, Greg Ewing
declaimed the following:
>On 7/09/21 11:38 am, Avi Gross wrote:
>
>> #define INDEFINITELY_LOOP while (true)
>>
>> So, how to do something like that in python, is a challenge left to the user
>> ?
>
>def hell_frozen_over():
> return False
>
>whil
Grant Edwards writes:
> On 2021-09-06, Stefan Ram wrote:
>> "Avi Gross" writes:
>>> In languages like C/C++ there are people who make up macros like:
>>>#define INDEFINITELY_LOOP while (true)
>>>Or something like that and then allow the preprocessor to replace
>>>INDEFINITELY_LOOP with valid C
On Tue, 07 Sep 2021 14:53:29 +, Grant Edwards wrote:
> On 2021-09-06, Stefan Ram wrote:
>> "Avi Gross" writes:
>>> In languages like C/C++ there are people who make up macros like:
>>>#define INDEFINITELY_LOOP while (true)
>>>Or something like that and then allow the preprocessor to replace
On 2021-09-06, Stefan Ram wrote:
> "Avi Gross" writes:
>> In languages like C/C++ there are people who make up macros like:
>>#define INDEFINITELY_LOOP while (true)
>>Or something like that and then allow the preprocessor to replace
>>INDEFINITELY_LOOP with valid C code.
>
> Those usually are
On 7/09/21 11:38 am, Avi Gross wrote:
#define INDEFINITELY_LOOP while (true)
So, how to do something like that in python, is a challenge left to the user 😉
def hell_frozen_over():
return False
while not hell_frozen_over():
--
Greg
--
https://mail.python.org/mailman/listinfo/py
ython-list@python.org
Subject: Re: on writing a while loop for rolling two dice
"Avi Gross" writes:
> In languages like C/C++ there are people who make up macros like:
>#define INDEFINITELY_LOOP while (true)
>Or something like that and then allow the preprocessor to replace
>IND
RESEND with clarification!
On Mon, 6 Sep 2021 20:11:41 -0400, Avi Gross via Python-list
declaimed the following:
>changing. Ages ago we had code that processed MTA headers and every time we
>had a meeting of standards bodies, we kept adding ever more headers and
Why did my mind immedi
On Mon, 6 Sep 2021 20:11:41 -0400, Avi Gross via Python-list
declaimed the following:
>changing. Ages ago we had code that processed MTA headers and every time we
>had a meeting of standards bodies, we kept adding ever more headers and
Why did my mind immediately flash on "The Man Who Ne
python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On 2021-09-06 at 20:11:41 -0400,
Avi Gross via Python-list wrote:
> And in the python version, has anyone made a generator that returned
> NULL or the like so you can say uselessly:
>
> for ( _ in forever(
On 2021-09-06 at 20:11:41 -0400,
Avi Gross via Python-list wrote:
> And in the python version, has anyone made a generator that returned
> NULL or the like so you can say uselessly:
>
> for ( _ in forever() ) ...
while "forever":
...
--
https://mail.python.org/mailman/listinfo/pyth
in the python version, has anyone made a generator that returned NULL or
the like so you can say uselessly:
for ( _ in forever() ) ...
-Original Message-
From: Python-list On
Behalf Of Stefan Ram
Sent: Monday, September 6, 2021 12:34 PM
To: python-list@python.org
Subject: Re: on wri
:50 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On Sat, 4 Sep 2021 12:27:55 -0500, "Michael F. Stemper"
declaimed the following:
>
>Kernighan and Ritchie agree(d) with you. Per _The C Programming
>Language__:
> Experience shows
condition" statement allows low-level emulation
of any loop... (same as Python "if condition: break"
loop-- "while" loop
exit when not condition;
...
end loop;
loop-- "rep
essage-
From: Python-list On
Behalf Of Hope Rouselle
Sent: Thursday, September 2, 2021 10:42 AM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
David Raymond writes:
>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x
"Michael F. Stemper" writes:
> On 04/09/2021 08.53, Hope Rouselle wrote:
>> Chris Angelico writes:
>
>>> And at this point, it's looking pretty much identical to the for loop
>>> version. Ultimately, they're all the same and you can pick and choose
>>> elements from each of them.
>> I see. That
-start->8---
>> >> def how_many_times():
>> >> x, y = 0, 1
>> >> c = 0
>> >> while x != y:
>> >> c = c + 1
>> >> x, y = roll()
>> >> return c, (x, y)
>> >
>> >>
>
hink a for-loop would improve
>> the readability here.
>
> It's on the cusp. When you ask someone to express the concept of "do
> this until this happens", obviously that's a while loop; but as soon
> as you introduce the iteration counter, it becomes less o
On 04/09/2021 08.53, Hope Rouselle wrote:
Chris Angelico writes:
And at this point, it's looking pretty much identical to the for loop
version. Ultimately, they're all the same and you can pick and choose
elements from each of them.
I see. That's why C must have added the do-while, but yea
s():
> >> x, y = 0, 1
> >> c = 0
> >> while x != y:
> >> c = c + 1
> >> x, y = roll()
> >> return c, (x, y)
> >
> >>
> >> Why am I unhappy? I'm wish I could confine x, y to the while loop.
> >>
def how_many_times():
x, y = 0, 1
c = 0
while x != y:
c = c + 1
x, y = roll()
return c, (x, y)
Since I haven't seen it used in answers yet, here's another option using our
new walrus operator
def how_many_times():
roll_count = 1
while (rolls := roll())[0] != rol
On Fri, Sep 3, 2021 at 4:51 AM Hope Rouselle wrote:
>
> Chris Angelico writes:
>
> > On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> > wrote:
> >>
> >> > def how_many_times():
> >> > x, y = 0, 1
> >> > c = 0
> >> > while x != y:
> >> > c = c + 1
> >> > x, y = roll()
> >> > retu
someone to express the concept of "do
this until this happens", obviously that's a while loop; but as soon
as you introduce the iteration counter, it becomes less obvious, since
"iterate over counting numbers until this happens" is a quite viable
way to express this. Howev
Chris Angelico writes:
> On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> wrote:
>>
>> > def how_many_times():
>> > x, y = 0, 1
>> > c = 0
>> > while x != y:
>> > c = c + 1
>> > x, y = roll()
>> > return c, (x, y)
>>
>> Since I haven't seen it used in answers yet, here's another
David Raymond writes:
>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x != y:
>> c = c + 1
>> x, y = roll()
>> return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our
> new walrus operator
>
> def how_many_times():
> roll_co
c + 1
>> x, y = roll()
>> return c, (x, y)
>
>>
>> Why am I unhappy? I'm wish I could confine x, y to the while loop. The
>> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
>> would you write this?
>
>>
On 30/08/2021 06:17, dn via Python-list wrote:
OTOH the simulation of rolling n-number of dice, as would happen in the
real-world, would be broken by making the computer's algorithm more
efficient (rolling until the first non-equal value is 'found'). Does
that mean the realism of the model dies?
On Tue, Aug 31, 2021 at 12:28 AM Peter Otten <__pete...@web.de> wrote:
>
> On 30/08/2021 15:50, Chris Angelico wrote:
>
> > def how_many_times():
> > return next((count, rolls) for count, rolls in
> > enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)
>
>
> That's certainly the most Coun
On 30/08/2021 15:50, Chris Angelico wrote:
def how_many_times():
return next((count, rolls) for count, rolls in
enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)
That's certainly the most Counter-intuitive version so far;)
Do I get bonus points for it being a one-liner that doe
On Mon, Aug 30, 2021 at 11:13 PM David Raymond wrote:
>
> > def how_many_times():
> > x, y = 0, 1
> > c = 0
> > while x != y:
> > c = c + 1
> > x, y = roll()
> > return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our
> new walrus operator
> def how_many_times():
> x, y = 0, 1
> c = 0
> while x != y:
> c = c + 1
> x, y = roll()
> return c, (x, y)
Since I haven't seen it used in answers yet, here's another option using our
new walrus operator
def how_many_times():
roll_count = 1
while (rolls := roll())[0] !=
On 30/08/2021 00.47, Peter Otten wrote:
> On 29/08/2021 12:13, dn via Python-list wrote:
>> On 29/08/2021 20.06, Peter Otten wrote:
>> ...
>>> OK, maybe a bit complicated... but does it pay off if you want to
>>> generalize?
>>>
>> def roll_die(faces):
>>> Â while True: yield random.randrang
On Mon, Aug 30, 2021 at 9:53 AM dn via Python-list
wrote:
>
> On 29/08/2021 22.24, Chris Angelico wrote:
> > On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> > wrote:
> >> Efficiency:
> >> - wonder how max( d ) == min( d ) compares for speed with the set() type
> >> constructor?
> >
> > That
On 29/08/2021 22.24, Chris Angelico wrote:
> On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> wrote:
>> Efficiency:
>> - wonder how max( d ) == min( d ) compares for speed with the set() type
>> constructor?
>
> That may or may not be an improvement.
>
>> - alternately len( d ) < 2?
>> - or
On 29/08/2021 12:13, dn via Python-list wrote:
On 29/08/2021 20.06, Peter Otten wrote:
...
OK, maybe a bit complicated... but does it pay off if you want to
generalize?
def roll_die(faces):
while True: yield random.randrange(1, 1 + faces)
def hmt(faces, dies):
for c, d in enumera
On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
wrote:
> Efficiency:
> - wonder how max( d ) == min( d ) compares for speed with the set() type
> constructor?
That may or may not be an improvement.
> - alternately len( d ) < 2?
> - or len( d ) - 1 coerced to a boolean by the if?
Neither of t
On 29/08/2021 20.06, Peter Otten wrote:
...
> OK, maybe a bit complicated... but does it pay off if you want to
> generalize?
>
def roll_die(faces):
> while True: yield random.randrange(1, 1 + faces)
>
def hmt(faces, dies):
> for c, d in enumerate(zip(*[roll_die(faces)]*dies), 1
On 28/08/2021 14:00, Hope Rouselle wrote:
def how_many_times():
x, y = 0, 1
c = 0
while x != y:
c = c + 1
x, y = roll()
return c, (x, y)
--8<---cut here---end--->8---
Why am I unhappy? I'm wish I could confine x, y to the
And there is the ever popular recursive version you call with no while loop
in sight. And, oddly, no variable declared in your main body:
# CODE START ---
import random
def roll2():
return random.randint(1,6), random.randint(1,6)
def roll_equal(counter):
first, second = roll2
On 28/08/2021 21:50, Hope Rouselle wrote:
>>> roll_count = 0
>>> while True:
>>> outcome = roll_two_dice()
>>> roll_count += 1
>>> if outcome[ 0 ]== outcome[ 1 ]: break
>>> return roll_count, outcome[ 0 ]
>>
>
> Wait, I'm surprised ``outcome'' is still a valid name at the
> return-sta
= 0
while x != y:
c = c + 1
x, y = roll()
return c, (x, y)
--8<---cut here---end--->8---
Why am I unhappy? I'm wish I could confine x, y to the while loop. The
introduction of ``x, y = 0, 1'' must feel like a trick to a
x, y)
>
> Why am I unhappy? I'm wish I could confine x, y to the while loop. The
> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
> would you write this?
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> """Rolls two d
Hope Rouselle writes:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> Hope Rouselle writes:
>>>How would you write this?
>>
>> """Rolls two dice until both yield the same value.
>> Returns the number of times the two dice were rolled
>> and the final value yielded."""
>> roll_count = 0
>> wh
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Hope Rouselle writes:
>>How would you write this?
>
> """Rolls two dice until both yield the same value.
> Returns the number of times the two dice were rolled
> and the final value yielded."""
> roll_count = 0
> while True:
> outcome = roll_two_
nd--->8---
>
> Here's my solution:
>
> --8<---cut here---start->8---
> def how_many_times():
> x, y = 0, 1
> c = 0
> while x != y:
> c = c + 1
> x, y = roll()
> return c, (x, y)
> --8<
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Hope Rouselle writes:
>>Wait, I'm surprised ``outcome'' is still a valid name at the
>>return-statement. Wasn't it defined inside the while? Shouldn't its
>>scope be restricted to the while block? I had no idea. I should learn
>>some Python.
>
>
s():
x, y = 0, 1
c = 0
while x != y:
c = c + 1
x, y = roll()
return c, (x, y)
--8<---cut here---end--->8---
Why am I unhappy? I'm wish I could confine x, y to the while loop. The
introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
would you write this? Thank you!
--
https://mail.python.org/mailman/listinfo/python-list
On 2020-05-22, DL Neil via Python-list wrote:
> On 23/05/20 4:31 AM, Grant Edwards wrote:
>> On 2020-05-22, Peter Otten <__pete...@web.de> wrote:
>>
>>> If you want to terminate the script you can use exit. However exit
>>> is a function, and you have to call it
>>>
>>> exit()
>>
>>
>>
>> Actu
On 5/22/2020 12:31 PM, Grant Edwards wrote:
On 2020-05-22, Peter Otten <__pete...@web.de> wrote:
If you want to terminate the script you can use exit. However exit
is a function, and you have to call it
exit()
Actually it's an instance of _sitebuiltins.Quitter not a function.
Which means
On 23/05/20 4:31 AM, Grant Edwards wrote:
On 2020-05-22, Peter Otten <__pete...@web.de> wrote:
If you want to terminate the script you can use exit. However exit
is a function, and you have to call it
exit()
Actually it's an instance of _sitebuiltins.Quitter not a function.
You still have
On 2020-05-22, Peter Otten <__pete...@web.de> wrote:
> If you want to terminate the script you can use exit. However exit
> is a function, and you have to call it
>
> exit()
Actually it's an instance of _sitebuiltins.Quitter not a function.
You still have to call it. ;)
--
Grant
--
https:
On 2020-05-22 7:49 a.m., John Yeadon via Python-list wrote:
> Am I unreasonable in expecting this code to exit when required?
Yes.
> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
> Â Â Â x = 2 ** (n - 1)
> Â Â Â sum += x
> Â Â
On Friday, May 22, 2020, at 7:49, John Yeadon via Python-list wrote:
> Am I unreasonable in expecting this code to exit when required?
Yes. :-)
> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
> x = 2 ** (n - 1)
>
John Yeadon via Python-list wrote:
> Am I unreasonable in expecting this code to exit when required?
It is unreasonable to expect something that doesn't match what you read in
the tutorial ;)
If you want to terminate the script you can use exit. However exit is a
function, and you have to call
No not really. If you use a breakpoint and a debugger you will find out
that your code continues till 2 M is met and then stops printing numbers
continuously.
On Fri, 22 May, 2020, 5:20 pm John Yeadon via Python-list, <
python-list@python.org> wrote:
> Am I unreasonable in expecting this code to
On Fri, May 22, 2020 at 7:51 AM John Yeadon via Python-list
wrote:
>
> Am I unreasonable in expecting this code to exit when required?
>
>
> # Add up the powers of 2 starting with 2**0 until 2 million is met.
> n = 1
> target = 200
> sum = 0
>
> while True:
> x = 2 ** (n - 1)
> sum +
Am I unreasonable in expecting this code to exit when required?
# Add up the powers of 2 starting with 2**0 until 2 million is met.
n = 1
target = 200
sum = 0
while True:
x = 2 ** (n - 1)
sum += x
print(n, sum)
if sum >= target:
print("Target met.")
exit
tion.
At least the title of the post: "How can i stop this Infinite While
Loop" is descriptive. Compared with some first-time poster's titles,
this is clear and competent. Thanks!
Thinking about it though, is there a hint of the nature of the problem,
or even then an answer, in t
ferzan saglam wrote:
> On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote:
>> rounds = 0
>> while rounds <= 10:
...
> Thanks, it Works superbly.
> To get the limit of 10 i wanted, i had to make a slight change:
> while rounds <= 9 .
That's the (in)famous "off by one"
On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote:
> m 30/10/2019 08:55, ferzan saglam escreveu:
> > total = 0
> > while True:
> >
> >print('Cost of item')
> >item = input()
> >
> >if item != -1:
> > total += int(item)
> >else:
> > break
> >
> > print
> On Oct 30, 2019, at 4:55 AM, ferzan saglam wrote:
>
> I have tried many ways to stop the infinite loop but my program doesn't seem
> to stop after 10 items! It keeps going...!)
>
> ---
> total = 0
> while True:
> item = input()
> if item != -1:
If you try this in the REPL, you'll see that 'item' is a string. You're
trying to compare it to an integer, which will always fail.
The cheapest way to fix this is probably:
if item != '-1':
Best,
G
--
https://
m 30/10/2019 08:55, ferzan saglam escreveu:
total = 0
while True:
print('Cost of item')
item = input()
if item != -1:
total += int(item)
else:
break
print(total)
The program does not stop because its code does not contain any deals
that make the loop stop after 10 rounds
>From what I understand you want to give the user the possibility to try 10
times or enter -1 to end the script, right?
If so, you need to check if item is -1 or total tries are already 10 and in
such a case break the loop.
No need for an else branch.
Note, input returns an str object but you compa
I have tried many ways to stop the infinite loop but my program doesn't seem to
stop after 10 items! It keeps going...!)
---
total = 0
while True:
print('Cost of item')
On 2017-09-02 18:53, Charles Hixson wrote:
python3 --version
Python 3.5.3
Running on Debian stretch
In this code s is a string parameter
while (j < k and \
(s[j].isalnum()) or \
(s[j] in seps and s[j+1].isalnum()) ):
j = j + 1
print ("i = {0}, j =
Charles Hixson wrote:
> python3 --version
> Python 3.5.3
>
> Running on Debian stretch
>
> In this code s is a string parameter
>
> while (j < k and \
> (s[j].isalnum()) or \
>(s[j] in seps and s[j+1].isalnum()) ):
> j = j + 1
> print ("i = {0}, j = {1
python3 --version
Python 3.5.3
Running on Debian stretch
In this code s is a string parameter
while (j < k and \
(s[j].isalnum()) or \
(s[j] in seps and s[j+1].isalnum()) ):
j = j + 1
print ("i = {0}, j = {1}, k = {2}, len[s] = {3}". \
format(i,
In <0c642381-4dd2-48c5-bb22-b38f2d5b2...@googlegroups.com>
paul.garcia2...@gmail.com writes:
> Write a program which prints the sum of numbers from 1 to 101
> (1 and 101 are included) that are divisible by 5 (Use while loop)
> x=0
> count=0
> while x<=100:
> if x%
On 29/11/2016 23:58, paul.garcia2...@gmail.com wrote:
Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are
included) that are divisible by 5 (Use while loop)
This is the code:
x=0
count=0
while x<=100:
if x%5==0:
count=count+x
x=x+1
print(count)
T
On 2016-11-29 23:58, paul.garcia2...@gmail.com wrote:
Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are
included) that are divisible by 5 (Use while loop)
This is the code:
x=0
count=0
while x<=100:
if x%5==0:
count=count+x
x=x+1
print(co
Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are
included) that are divisible by 5 (Use while loop)
This is the code:
x=0
count=0
while x<=100:
if x%5==0:
count=count+x
x=x+1
print(count)
Question: How does python know what count means
Elizabeth Weiss wrote:
> words=["hello", "world", "spam", "eggs"]
> counter=0
> max_index=len(words)-1
>
> while counter<=max_index:
> word=words[counter]
> print(word + "!")
> counter=counter + 1
while 0 < 10:
get 0'th element
do something with element
increment 0 to 1
(repeat)
words[0
f the loop body.
But with 'else', if you see the message it means the while statement has
been entered. Here:
if cond:
while n>=x:
n=n-1
print "*"* n
else:
print ("2nd loop exit n=",n,"x=",x)
Lawrence is right
BartC wrote:
> On 12/10/2016 05:30, Lawrence D’Oliveiro wrote:
>> On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote:
>>> while n>=x:
>>> n=n-1
>>> print "*"* n
>>> else:
>>> print ("2nd loop exit n=",n,"x=",x)
>>
>> What is the difference between that and
>>
>> w
On 12/10/2016 05:30, Lawrence D’Oliveiro wrote:
On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote:
while n>=x:
n=n-1
print "*"* n
else:
print ("2nd loop exit n=",n,"x=",x)
What is the difference between that and
while n>=x:
n=n-1
print "*"*
On 11/10/2016 22:26, Lawrence D’Oliveiro wrote:
On Wednesday, October 12, 2016 at 6:58:46 AM UTC+13, dhawan...@gmail.com wrote:
Only first loop is executing not the second one?
n=6
x=1
while x<=n:
print("*"*x)
x+=1
print('n=', n)
dhawanpawa...@gmail.com writes:
> n=6
> x=1
> while x<=n:
> print "*"*x
> x+=1
> while n>=x:
> n=n-1
> print "*"* n
>
>
> Only first loop is executing not the second one?
It's a basic fact about while loops that after the loop the condition is
false. The two conditions x <= n a
On 10/11/2016 11:58 AM, dhawanpawa...@gmail.com wrote:
>
> n=6
> x=1
> while x<=n:
> print "*"*x
> x+=1
> while n>=x:
> n=n-1
> print "*"* n
>
>
> Only first loop is executing not the second one?
Did you try printing out the loop variable to see what it does and what
it is aft
On Tue, Oct 11, 2016 at 1:58 PM, wrote:
>
> n=6
> x=1
> while x<=n:
> print "*"*x
> x+=1
> while n>=x:
> n=n-1
> print "*"* n
>
>
> Only first loop is executing not the second one?
Because after the first loop n < x
--
https://mail.python.org/mailman/listinfo/python-list
1 - 100 of 397 matches
Mail list logo