To my understanding, a gene consists of a unique sequence of nucleotides that codes for a polypeptide or an RNA molecule. In my textbook, it is stated that DNA codes for protein molecules. So I thought, a gene only code for 1 protein molecule or 1 RNA molecule However, DNA can code for a number of protein molecules or RNA molecules, as a gene is a stretch of DNA. Is my understanding correct?
Your understanding is correct in that DNA encodes RNA, and this is a one-to-one relationship generally (although there are exceptions, see link below). However, a given RNA can encode myriad proteins via translation. This is because of different translation start sites and splicing of RNA. You can read about this relationship between DNA/RNA/protein (the 'central dogma' of molecular biology), here:
But in the title of the quesiton you also ask about whether a gene or DNA encodes protein. A gene is comprised of DNA; if someone talks about a gene, this just means a transcribed sequence, i.e. a region of DNA that is made into RNA. Whether or not this is then translated does not impact its definition as a gene. If it is transcribed, you could call it a 'protein-coding gene', otherwise you can call it a 'non-coding gene'.