My crappy guessing game went from 40 lines to 12 after I finally got loops
I started learning Python about 6 weeks ago and last Tuesday I rewrote my number guessing game at the kitchen table in about 20 minutes. The first version was literally 40 lines with the input and the if checks copied and pasted five times, and it broke if you guessed wrong more than twice. After I watched a free video on while loops, it dropped to 12 lines and now it just keeps asking until you get it, even if that takes 30 tries. What was the first thing that clicked for you and made your old code look silly?
Learned in a book once that the moment code gets copy pasted more than twice, that is your brain telling you a loop belongs there. My own first guessing game had six ugly blocks of the same if check until I moved it into a while loop and the whole thing shrank in half. It really is a great feeling when the answer was sitting right there the whole time.