Anti spam with questions or numbers

My site has always been targeted by spams for some reason. I want to write a code to prevent this. I know some people use captchas. but I would prefer to know the idea or concept to against the spams.

How entering numbers or answering questions can help us to stop the spams - I still don’t get it yet…?

for instance, how answering the questions below can do the magic?

‘What is 3 times nine?’
‘What number is half a dozen?’

It would be great if you can give me some hint to make this code from scratch…

otherwise, any other programmes like captchas?

many thanks,

It can’t stop people, but it can stop spambots. Of course, the more evolved the spambots get, the more the anti-spam measures must evolve as well.