Python Forum
won't exit a loop, please help
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
won't exit a loop, please help
#3
Hi, I'm new to python, about a couple of months learning on my own,
I see that people are very helpful on this forum, I have a dilemna on this program I'm writing.
It would seem that the print ("test") statement should not print, when user enters "N" because the flag redo is set to "1"
yet it still runs that line of code.







Here is the program.

import os
class klass:
     '"docstring'"
    def_init_(self):
        self.attribute="var"
        if len(self.attribute) <2:
            pass


#my program snippet starts here
redo=0
while redo==0:
    srch=0
    while srch==0:
        user=input("would you like to do a search of the list? (Y/N) ")
        if user=="n":
            srch=1
            redo=1
    print ("test")
print ("done")
Reply


Messages In This Thread
I'll be back - by hobbyprogrammer - Oct-22-2018, 03:26 AM
RE: won't exit a loop, please help - by Larz60+ - Oct-22-2018, 11:19 AM
RE: won't exit a loop, please help - by stullis - Oct-22-2018, 11:22 AM
RE: won't exit a loop, please help - by jdjeffers - Oct-22-2018, 11:44 AM
won't exit a loop, please help - by hobbyprogrammer - Oct-22-2018, 03:47 AM
snippet of code of same problem I posted before - by hobbyprogrammer - Oct-22-2018, 04:24 AM
RE: I'll be back - by Larz60+ - Oct-22-2018, 04:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,915 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  While loop doesn't exit KenHorse 3 2,066 Jun-20-2021, 11:05 PM
Last Post: deanhystad
  Exit Function - loop Tetsuo30 2 2,107 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  Struggling to exit this while loop fatherted99 5 2,546 Feb-08-2020, 07:46 PM
Last Post: fatherted99
  Using break to exit a loop help JJG 4 4,238 Dec-09-2017, 03:02 AM
Last Post: JJG
  How to exit infinite While Loop? Fran_3 3 4,146 Aug-10-2017, 05:29 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020