How to fix infinite loop in python

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I just started with python and RPi. But i stuck :D I have 4 microswitches, and few posibilities (BC1, BC2, BC3... etc). For example, if we choose posibility BC1, then microswitch 1 (btn1) and 2 (btn2) must be active, if that case is true, then ledG1 and vazduh are active. Also I need to have a posibiliti to insert another posibiliti (BC1, BC2, BC3), and untill we insert another posibility first must be active (if requested switches are active).

With this de">code it's working, but ask me only once to insert possibility.

BC1 = '1'
BC2 = '2'
BC3 = '3'
BC4 = '4'
BC5 = '5'

def compare ():
    while True:
        Barde">code = input("Insert barde">code: ")
        while Barde">code == BC1:
            if GPIO.input(btn1)==0 and GPIO.input(btn2)==0:
                GPIO.output(vazduh, GPIO.HIGH)
                GPIO.output(ledG1, GPIO.HIGH)
                continue
            else:
                GPIO.output(vazduh, GPIO.LOW)
                GPIO.output(ledG1, GPIO.LOW)
                continue                
        while Barde">code == BC2:
            if GPIO.input(btn2)==0 and GPIO.input(btn4)==0:
                GPIO.output(vazduh, GPIO.HIGH)
                GPIO.output(ledG3, GPIO.HIGH)
                continue
            else:
                GPIO.output(vazduh, GPIO.LOW)
                GPIO.output(ledG3, GPIO.LOW)
                continue

profilepic.png
manpreet 2 years ago

I think you probably wanted to use if instead of while in your first while's scope.

while True:
   Barcode = input("Insert barcode: ")
   if Barcode == BC1:
      #Do something #1
   if Barcode == BC2:
      #Do something #2

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.