"Do you have a book?"
Translation:האם יש לךָ ספר?
It's not about the question being formal or not. It's about the situation, setting.
It's formal if you talk to your boss, or some important person, your superior. Or radio and TV anchors speak this way, many teachers, academic persons, or in certain religious settings.
It's informal if you talk to your friends, family, colleagues, classmates.
The difficulty is determining which situation this is, since it is an isolated sentence. In that case, both versions should be accepted.