Python Forum
1st Project Guess between 1 and 20
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
1st Project Guess between 1 and 20
#2
There is nothing at all wrong with your code that I can see. In terms of being concise, you could technically get by with just "else" on line 8 instead of your "elif" clause, but there is nothing wrong with being explicit here and some may prefer it. (Personally, I try to stick with "else" when the condition is binary like this one. Because your "if" condition is unsatisfied, you know your "elif" condition will be satisfied without explicitly checking for it.) You could also theoretically get by without differentiating between floats and strings (lines 12-18) since you really only care whether you have a valid integer or not, but what you did is cleverly implemented and certainly not incorrect.

Great job! Things you might consider adding:
-A check to see if the user entered a number below 1 (the same way you check for a number above 20)
-A guess count to show the user how many guesses they needed to win
-A prompt to let the user play again after a round is over
Reply


Messages In This Thread
1st Project Guess between 1 and 20 - by MiNigle - May-31-2020, 09:35 AM
RE: 1st Project Guess between 1 and 20 - by GOTO10 - May-31-2020, 03:05 PM
RE: 1st Project Guess between 1 and 20 - by MiNigle - May-31-2020, 06:44 PM
RE: 1st Project Guess between 1 and 20 - by NectDz - May-31-2020, 04:11 PM
RE: 1st Project Guess between 1 and 20 - by GOTO10 - May-31-2020, 04:24 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020