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
#3
(May-31-2020, 09:35 AM)MiNigle Wrote:
# Guessing Game

def string_or_integer(guess):
    while True:
        if guess in ('quit', 'Quit'):
            print('Bye bye!')
            sys.exit()
        elif not guess in ('quit', 'Quit'):
            try:
                return int(guess)
            except ValueError:
                try:
                    float(guess)
                    print("Please use whole numbers")
                    guess = input('>>> ')
                except ValueError:
                    print ("This is not a number. Please enter a number between 1 and 20")
                    guess = input('>>> ')
Very nice code, I see in your type 'Quit' to give up you could of made it more effective and simpler. Let's say they type qUiT the program does not know what to do. I would like for you to take a look of my guessing game when I first started out where I did the same concept. https://repl.it/@KEVINGRANADOS1/GuessNumber take a look on line 43 and try to experiment with it, it is much simpler and efficient.
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