If restricted morphism of ringed spaces are equal, then they are actually equal

Given any two ringed spaces $$(X, \mathcal O_X)$$ and $$(Y, \mathcal O_Y)$$, let $$\{ U_\lambda\}_{\lambda \in \Lambda}$$ be an open covering of the topological space $$X$$. If $$f,g: (X, \mathcal O_X) \to (Y, \mathcal O_Y)$$ are morphism of ringed spaces such that $$f|_{\lambda} = g|_{\lambda}, \ \forall \lambda \in \Lambda,$$ then prove that $$f=g.$$

I'm stuck after writing definitions in detail. Any help or hint will be appreciated.

Thus the key part is to show that $$f^\sharp=g^\sharp$$ as morphisms from $$\newcommand\calO{\mathcal{O}}\calO_Y\to f_*\calO_X=g_*\calO_X$$.
Let $$V$$ be an open subset of $$Y$$. Let $$a\in\calO_Y(V)$$. Let $$\newcommand\inv{^{-1}}U=f\inv(V)=g\inv(V)$$. Then $$f^\sharp(a),g^\sharp(a)\in \calO_X(U)$$ by definition. Then $$\{U_\lambda\cap U\}_{\lambda\in\Lambda}$$ gives an open cover of $$U$$, and since $$f|_{U_\lambda}=g|_{U_\lambda}$$, we have that $$f^\sharp(a)|_{U\cap U_\lambda}=g^\sharp(a)|_{U\cap U_\lambda}$$. Then since $$f^\sharp(a)$$ and $$g^\sharp(a)$$ are equal on an open cover of $$U$$, we must have that $$f^\sharp(a)=g^\sharp(a)$$ since $$\calO_X$$ is a sheaf. Thus since $$a$$ and $$V$$ were arbitrary, $$f^\sharp=g^\sharp$$.
To clarify why $$f^\sharp(a)$$ agreeing with $$g^\sharp(a)$$ on an open cover of $$U$$ implies that they are equal, this is one of the axioms of sheaves. On wiki, this is the locality axiom. The axiom says that if $$F$$ is a sheaf, and $$a,b\in F(U)$$, and $$\{U_i\}$$ is a cover of $$U$$, then if $$a|_{U_i}=b|_{U_i}$$ for all $$i$$, then $$a=b$$.
• Why "since $f^\sharp(a)$ and $g^\sharp(a)$ are equal on an open cover of $U$, we must have that $f^\sharp(a)=g^\sharp(a)$ since $\calO_X$ is a sheaf" holds automatic? I couldn't say this impliance from the definition of the sheaf. – user621469 Dec 1 '18 at 22:45