This is for educational purposes, please do not use this code to do any harm. I'm not responsible for your actions. ddosing is a crime and can lead to jail.
When you think of DDOS you think of a more complex situation where a hacker is using code to deny service from a provider, and that is not true denying of service can be easily done using everyday applications for example if i run 100 web browsers trying to access a small business site that web server from that small business is being put under huge loads of stress meaning any of their customers trying to access their site can lead to slow load times or even no loading at all with a prompt Time out.
in this example i have a MSDOS script where the script will execute 20 browsers loading the target "google.com" and depending on the server we would have to run more browsers requesting more resources to deny more service.
Usually to combat against DDOS a server can increase or decrease their server resources, identify what is normal traffic and what isn't or even deploy firewall rules to prevent further attacks.
a more complex way and in code would be to code a client to connect to an IP address (server) and port and constantly send data and then upscale the client amount to take up all the server's resources which i will later provide a more complex example of.