Created
March 2, 2020 00:39
-
-
Save lchenneberg/3a0ce48a7d4eb21717002ef27ae3c834 to your computer and use it in GitHub Desktop.
Eduonix eGrade - AI - ML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def requestValidNum(message, min=None, max=None ): | |
num = None | |
while isinstance(num, int) != True: | |
try: | |
numStr = input(message) | |
tempNum = int(numStr) | |
if min != None and min > tempNum : | |
print(f'{min} is the min value allowed!') | |
continue | |
if max != None and max < tempNum : | |
print(f'{max} is the max value allowed!') | |
continue | |
num = tempNum | |
except: | |
print(f'\'{numStr}\' is not an integer!') | |
return num | |
numberOfGames = requestValidNum('how many games would you like to play? ') | |
for gameNum in range(1, numberOfGames + 1): | |
print(f"Game {gameNum}!") | |
numToBeGuessed = random.randint(1, 25) | |
inputedNumber = None | |
numOfAttempts = 0 | |
while inputedNumber == None: | |
numOfAttempts += 1 | |
tempNum = requestValidNum(f"Choose a number between 1 and 25: ", min=1, max=25) | |
if tempNum > numToBeGuessed: | |
print(f'The number to be guessed is less than {tempNum}!') | |
continue | |
elif tempNum < numToBeGuessed: | |
print(f'The number to be guessed is greater than {tempNum}!') | |
continue | |
else: | |
inputedNumber = tempNum | |
print(f'Congratulation, you have guessed {inputedNumber} after {numOfAttempts} attempts!') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment