def settings(): display_menu_title('Settings', 25) answer = input('Do you want to change the MAX_VALUE?(y/n):') if answer == 'y': global MAX_VALUE MAX_VALUE = int(input('new value = ')) elif answer == 'n': return else: print('Invalid answer.')
def addition(): display_menu_title('Addition', 25) print('Answer with 0 if you want to stop.') running = True global points while running: a = b = 0 print('Points:', points) a = random.randint(1, 100) b = random.randint(1, 100) result = int(input('Task: {} + {} = '.format(a, b))) if result == a + b: points += 1 elif result == 0: running = False print()
def new_game(): low = 0 high = MAX_VALUE lucky = random.randint(low, high) searching = True tryes = 0 middle = round(high / 2) numbers = [] display_menu_title('Game Start', 27) print('Help: start with MAX_VALUE / 2 =', middle) while searching: n = int(input('Guess {}: '.format(tryes + 1))) if n < 0: print('Number can\'t be negative.\n') continue elif n <= low or n >= high: print('Number is not between high and low values.\n') continue numbers.append(n) print('Result =', end=' ') if n == lucky: print('EQUAL') searching = False else: if n > lucky: print('HIGH') high = n else: print('LOW') low = n tryes += 1 print('Help:', end=' ') print('High =', high, end=' ') print('Low =', low, end=' ') middle = round((high - low) / 2 + low) print('Middle =', middle) print('Possible numbers count:', high - low - 1, end='\n\n') statistics(numbers, lucky)
def statistics(): global points display_menu_title('Statistics', 30) print('Points:', points)
def instructions(): display_menu_title('Instructions', 30) print('The computer have a number between 0 and MAX_VALUE.') print('MAX_VALUE by default is 100. You can set it in Settings.') print('Your mission is to find the number.')
def statistics(numbers, lucky): display_menu_title('Statistics', 30) for n in range(len(numbers)): print('Try {} Number = {} Result = {}'.format( n + 1, numbers[n], 'LOW' if numbers[n] < lucky else 'HIGH' if numbers[n] > lucky else 'EQUAL'))