Re: How can i stop this Infinite While Loop - Python

2019-11-01 Thread DL Neil via Python-list
TLDR; declare if homework; doing someone's homework doesn't really help; Python is not ALGOL/Pascal/C/C++ by any other name; Python assignments should promote learning semantics as well as syntax; sometimes re-stating the problem leads to an alternate/better solution. On 31/10/19 12:55 AM, fe

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Peter Otten
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"

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread ferzan saglam
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

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Irv Kalb
> 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:

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Gunnar Þór Magnússon
> 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://

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Matheus Saraiva
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

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Eko palypse
>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