I have done something differently on the For Loops section. Would this be good or bad practice?


It works overall for the basic idea of the assignment, and that is to allow the Player to make 5 guesses.

I wouldn’t call it a good practice for two reasons:

  1. You’re calling Input_Guess outside of the loop once, then iterating 4 times. While there are situations where that would be the way to go, this is not one of them. It would be better to remove that external call to Input_Guess and increase your loop’s count limit by 1.

  2. On line 37, you initialize Player_Guesses with the return value of Input_Guess. That in and of itself is a pretty slick way of doing it and is not where my personal issue lies. The problem lies in that you’re doing this initialization inside of the loop. While it doesn’t break your code (I tried it in my own and it worked just fine), best practice is to initialize your variables at the beginning of the scope in which they’re used. In this case, just before you start your for-loop.

While these are my own personal opinion, the important thing to keep in mind is whether your code works or not. And I see no real reason why it wouldn’t. :smiley:

Privacy & Terms