Oct-26-2022, 09:17 AM
Anyone can get it right if you use endless looping!
That must be curtailed!
That must be curtailed!
def myApp(): import random rNum = random.randint(1, 20) #rNum = 5 hint = len(str(rNum)) def tooBig(num): print('Number is too big!') anum = input('Guess again Dummkopf ... ') return int(anum) def tooSmall(num): print('Number is too small!') anum = input('Guess again Dummkopf ... ') return int(anum) print('Guess the random number!') print('The random number is', len(str(rNum)), 'long.') print('The number is', hint, 'digit(s) long.') # first guess anum = int(input('Guess what the random number is! Enter your guess here ... ')) count = 1 # could give them more guesses or better hints for longer numbers for i in range(5, 0, -1): print('You have', i, 'guesses left') if anum == rNum: print(f'Well done, you got it in', count, 'guess(es)!') break if anum < rNum: anum = tooSmall(anum) elif anum > rNum: anum = tooBig(anum) count +=1 # if loop ended unsuccessfully if anum != rNum: print('Loser!')