How would I make a switch between multiple variables using a single switch variable?
Update: To clarify the intent is to switch back between these two sets of variables an indefinite amount of times.
When I try this I get the following error.
a1= 'process1'
a2 = 'process2'
b1 = 'action1'
b2 = 'action2'
switch = True # the switch to indicate which set of variables to use
N = 10 # the number of times to switch between the two sets of variables
# alternate between two sets of variables N times
for i in range (N):
active_process, active_action = a1, b1 if switch else a2, b2
print("active_process: %s, active_action is: %s" %(active_process, active_action))
switch = not switch
Traceback:
Traceback (most recent call last):
File "/home/username/.PyCharm2019.3/config/scratches/scratch_10.py", line 10, in <module>
active_process, active_action = a1, b1 if switch else a2, b2
ValueError: too many values to unpack (expected 2)
Process finished with exit code 1
iorswitchhere:for response, greeting in (a1, b1), (a2, b2):.responses = ['yes', 'no']; greetings = ['hello', 'goodby']; for response, greeting in zip(responses, greetings):for ap, aa in islice(cycle([(a1,b1), (a2,b2)]), N):(whereisliceandcycleare imported fromitertools). Or if you need/wanti,for i, (ap, aa) in zip(range(N), cycle(...)).(a1, b1) if switch else (a2, b2).