From the course: Introduction to Python: Learn How to Program Today with Python by Pearson

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Improve the number-guessing game with "while" loops

Improve the number-guessing game with "while" loops

So, now let's look at improving our number guessing game using while loops. And this is using a, you know, often what people will say is, like, keep it dry, which means don't repeat yourself. So that's a common, what's called a code smell, which I'll talk more about code smells at at the end of this lesson, but that's one of them. If you see a bunch of repetition, that is a good candidate for refactoring. And it probably, if you've done any programming at all, it probably really hurt you to have to repeat all of this multiple times. So let's go open up challenge for number guests. I'm working from the one that does not use functions, just having all of that repetition and asking for the guess three times. So in order to refactor this to use loops, we will look, this is all the stuff that we wanna repeat. So just above it, I'm gonna say while and then some condition. So maybe our condition is going to be, well, let's just add while true for now. And then I will indent all of that. And…

Contents