In small programs, it's easy to use copy-and-paste.
Do not do this.
If you observe commonality, write a function.
Even better, do detailed design before implementing so that functions reveal themselves early on.