The Berlin Wall was built to keep Eastern Germans from leaving their country. This separation was a physical barrier that divided East and West Berlin, constructed by the German Democratic Republic (East Germany) to prevent its citizens from fleeing to West Germany. It was erected in 1961 and stood as a symbol of the ideological divide between the communist Eastern Bloc and the capitalist Western Bloc during the Cold War.
The wall was not built to keep Western spies out or to show the West its impotence. These options are not accurate reasons for the construction of the Berlin Wall.
Preventing flooding in the former German capital was also not the purpose of the Berlin Wall. The main intention behind its construction was to halt the mass exodus of East Germans seeking political freedom and better living conditions in the West.