Feedback a number when meet a condition

Hi there. I am using PsychoPy3 and trying to design a experiment that will give the participants a feedback after they press keys. Some keys will feedback a fixed number, but some keys have two feedback, which feedback would be chosen is determind by probability,for example, if participant press A, he/she will 100% get a feedback number"100", if he/she press B, the feedback 50% will be 0, and 50% will be 200. I write some code, but it didn’t work, I don’t know how to fix it
the error and code is below:

error:
File “C:\Users\real_\Desktop\experience_lastrun.py”, line 566, in
res = gui.Dlg(int(‘1 2 3 4’))
ValueError: invalid literal for int() with base 10: ‘1 2 3 4’

code:
from psychopy import gui
import random
res = gui.Dlg(int(‘1 2 3 4’))
res.addField(int(‘1 2 3 4’))
res.show()
rand_num = random.random()

feedback =
if res == 1:
feedback = 100
elif res == 2 and rand_num<0.2:
feedback = 500
elif res == 3 and rand_num<0.5:
feedback = 200
elif res == 4 and rand_num<0.1:
feedback = 1000
else:
feedback = 0

It’s because you’re trying to convert the string '1 2 3 4' to an integer rather than each number. Instead you should do:

[1, 2, 3, 4]

thanks for reply, I changed the code to

res = gui.Dlg(int(1,2,3,4))
res.addField(int(1,2,3,4))
but it still tell me
ValueError: invalid literal for int() with base 10: ‘1,2,3,4’
I try to remove the“gui.Dlg”,now it tell me

TypeError: int() takes at most 2 arguments (4 given)
is this the system defect?

Why are you using int?

int(1,2,3,4) doesn’t make sense.

If necessary you could use int(1),int(2),int(3),int(4)

Thks for reply, well, in fact, I just want to make a keypress feedback for each of the risky choices, then I thought if use key H,J,K,L, it might took participants’ working memory space, so I thought choose key1,2,3,4 might solve this problem. I search the manual but didn’t find how to define a keypress response that fit my research, so I used the int. use int(1) is a good idea, I’ll try it. Thks

You might not need int at all if you are trying to define keys in a dialogue box. Try ['1','2','3','4']

I use the [1,2,3,4], and the code is below

from psychopy import gui
import random
res = keyboard.Keyboard(1,2,3,4)
rand_num = random.random()

feedback=
if res == keyboard.Keyboard(1):
feedback = ‘100’
elif res == keyboard.Keyboard(2) and rand_num<0.2:
feedback = ‘500’
elif res == keyboard.Keyboard(3) and rand_num<0.5:
feedback = ‘200’
elif res == keyboard.Keyboard(4) and rand_num<0.1:
feedback = ‘1000’
else:
feedback = ‘0’
now it return feedback when I press 1, but the feedback is “”, not the “100”. Is this because I code the feedback in begin routine? should I code the feedback begin experiment

You need some code like keys = res.getKeys() or keys = res.waitKeys() to query the keyboard.

Then use if '1' in keys: etc

Thks, it works, but next problem is coming, I will try to fix it myself, if I fail, I would like to ask you again, Thks a lot