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.
#21
After entering what you have on line 3, enter the following code:
and button1_pressed and button2_pressed
Reply
#22
Try the following
do_some_first = False   
while True:
    do_some = button1_pressed() and button2_pressed()
    do_some2 = button3_pressed()

    if do_some and not do_some2:
        do_some_first = True
    elif not do_some:
        do_some_first = False

    if not do_some_first:
        do_some2 = False

    if do_some:
        print('do some')

    if do_some2:
        print('do some2')
Reply
#23
(May-31-2020, 09:44 PM)Yoriz Wrote: Try the following
do_some_first = False   
while True:
    do_some = button1_pressed() and button2_pressed()
    do_some2 = button3_pressed()

    if do_some and not do_some2:
        do_some_first = True
    elif not do_some:
        do_some_first = False

    if not do_some_first:
        do_some2 = False

    if do_some:
        print('do some')

    if do_some2:
        print('do some2')

it seems that when button3 is pressed do_some and do_some2 are true at same time, than the result is:

Output:
do some2 do some do some2 do some do some2 do some do some2 do some do some2 do some do some2 do some do some2 do some do some2 do some do some2 do some do some2 do some do some2
Reply
#24
Difinitely not the best way of doing it, but, like always, this should work:
isMPressed = False    
while True:
	while button1_pressed() and button2_pressed():
		print("do some")
		while button3_pressed() and not isMPressed: # Only if it is pressed after button1 and button2 are pressed
			isMPressed = False
			print("do some2")
			if button2_pressed() == 0:
				break # this only breaks the inner while loop 
		isMPressed = True if button3_pressed() else False
	isMPressed = True if button3_pressed() else False
Reply
#25
(Jun-01-2020, 08:02 AM)DreamingInsanity Wrote: Difinitely not the best way of doing it, but, like always, this should work:
isMPressed = False    
while True:
	while button1_pressed() and button2_pressed():
		print("do some")
		while button3_pressed() and not isMPressed: # Only if it is pressed after button1 and button2 are pressed
			isMPressed = False
			print("do some2")
			if button2_pressed() == 0:
				break # this only breaks the inner while loop 
		isMPressed = True if button3_pressed() else False
	isMPressed = True if button3_pressed() else False

works like a charm! Thank you again!!
Reply
#26
Im wondering a scenario a lit bit more complex... is there a way to keep almost the same result, but instead of buttom1 + buttom3 + buttom2 (in this order) resulting "do some",a way to it results "do some2"?
Reply


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 278 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  unable to remove all elements from list based on a condition sg_python 3 442 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 733 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Sent email based on if condition stewietopg 1 861 Mar-15-2023, 08:54 AM
Last Post: menator01
  Replacing values ​​in Mysql with a condition stsxbel 0 636 Mar-05-2023, 08:20 PM
Last Post: stsxbel
  create new column based on condition arvin 12 2,244 Dec-13-2022, 04:53 PM
Last Post: jefsummers
Question Running an action only if time condition is met alexbca 5 1,315 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 833 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  How to write the condition for deleting multiple lines? Lky 3 1,137 Jul-10-2022, 02:28 PM
Last Post: Lky
  Can I check multi condition for 1 item in a easy way? korenron 4 1,570 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