Python Forum
[HELP] Nested conditional? double condition followed by another condition.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] Nested conditional? double condition followed by another condition.
#5
(May-31-2020, 03:35 PM)Yoriz Wrote:
button1_pressed = True
button2_pressed = True
button3_pressed = True
button2_is_not_pressed = True

while button1_pressed and button2_pressed:
    print('do some') # this only happens if both the above are True
    while button3_pressed:
        print('do some2') #  theis only happens if button3_pressed is True
        if button2_is_not_pressed:
            break # this only breaks the inner while loop
    break # added an extra break else it would just be stuck in an endless outer loop
Output:
do some do some2
The following conditions nothing will happen
button1_pressed = False
button2_pressed = True
button3_pressed = True
button2_is_not_pressed = True

while button1_pressed and button2_pressed:
    print('do some') # this only happens if both the above are True
    while button3_pressed:
        print('do some2') #  theis only happens if button3_pressed is True
        if button2_is_not_pressed:
            break # this only breaks the inner while loop
    break # added an extra break else it would just be stuck in an endless loop
Output:
button1_pressed and button2_pressed must be returning True even though you think they should not be.

I really apreciate your help... but imagine this situation:

1 - user press button1 and button2 then press button3
Its ok to me "do some 2"
2 - user press button2 and button1 then press button3
Its ok to me "do some 2"

but

3 - user press button3 before button1 and button2
Its not ok to "do some2", I need just to "do some"

Mate, I should have mentioned that this whole code is inside a Main loop. Im sorry!!

So.. I Thinks to test should be like this:

button1_pressed = True
button2_pressed = True
button3_pressed = True
button2_is_not_pressed = True

while True:
    while button1_pressed and button2_pressed:
        print('do some') # this only happens if both the above are True
        while button3_pressed:
            print('do some2') #  theis only happens if button3_pressed is True
            if button2_is_not_pressed:
                break # this only breaks the inner while loop
        break # added an extra break else it would just be stuck in an endless outer loop
Reply


Messages In This Thread
RE: [HELP] Nested conditional? double condition followed by another condition. - by penahuse - May-31-2020, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 339 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  unable to remove all elements from list based on a condition sg_python 3 500 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 772 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Sent email based on if condition stewietopg 1 905 Mar-15-2023, 08:54 AM
Last Post: menator01
  Replacing values ​​in Mysql with a condition stsxbel 0 657 Mar-05-2023, 08:20 PM
Last Post: stsxbel
  create new column based on condition arvin 12 2,361 Dec-13-2022, 04:53 PM
Last Post: jefsummers
Question Running an action only if time condition is met alexbca 5 1,377 Oct-27-2022, 02:15 PM
Last Post: alexbca
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 877 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to write the condition for deleting multiple lines? Lky 3 1,197 Jul-10-2022, 02:28 PM
Last Post: Lky
  Can I check multi condition for 1 item in a easy way? korenron 4 1,612 May-01-2022, 12:43 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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