n
18

I was writing the same code over and over for a week before I learned about functions

I was making a simple number guessing game in Python and kept copying my 'check the guess' logic every single time the player took a turn. After about seven copies, my friend looked at my screen and just said, 'You know you can make a function for that, right?' I felt so dumb. I rewrote it with one function and my code went from 50 messy lines to about 20 clean ones. Has anyone else had a basic concept like that just click way later than it should have?
2 comments

Log in to join the discussion

Log In
2 Comments
the_rowan
the_rowan15d ago
Welcome to the club, we meet on Tuesdays. I did the same thing with a bunch of print statements before realizing I could just loop them. The real fun starts when you figure out you can put functions inside other functions and your brain melts all over again.
5
jason524
jason52415d ago
Used to think functions were just extra work. Now I can't imagine coding without them.
4