I want to make a quiz using TeX that "looks like"
Problem 1) Let $f(x)=x^2$. Evaluate $f'(1)$.
Problem 2) Let $A$ be a matrix such that $$A=\begin{bmatrix}3&1\0&1\end{bmatrix}$$ What is the value of $|A|$?
Answer1) 2
Answer2) 3
And I made a TeX file "written as"
\documentclass{article}
\usepackage{amsmath,amssymb}
\newcounter{num}
\newcommand{\prob}{\par\bigskip\bigskip\noindent\refstepcounter{num}\textbf{Problem \arabic{num}) }}
\newcommand{\ans}{\par\bigskip\bigskip\noindent\refstepcounter{num}\textbf{Answer \arabic{num}) }}
\begin{document}
\prob
Let $f(x)=x^2$.
Evaluate $f'(1)$.
\prob
Let $A$ be a matrix such that
$$A=\begin{bmatrix}3&1\0&1\end{bmatrix}.$$
What is the value of $|A|$?
\setcounter{num}{0}
\ans
2
\ans
3
\end{document}
It prints the result pretty well, except for the fact that the problem statements and answers are separated.
I want to type answer 1 just after problem 1, which would prevent many kinds of errors.
How can I fix my code?

\begin{Exercise}but the format isn't what I want. Surely, the document offers many customization, but I think there is a lighter way to do it. – govindah Jan 03 '22 at 15:27