Jun-18-2018, 08:52 PM
from random import randint def get_msg(msg, subject, subject_mark): for i in range(1, doors+1): if i in subject: msg+=door % subject_mark else: msg+=door % ' ' return msg def get_input(msg, min_, max_): while True: s=input(msg) if s.isdigit() and min_ <= int(s) and int(s) <= max_: return int(s) else: print('Bad choice! Try again.') def get_ghost(): ghost = [] while True: rnd = randint(1, doors) if rnd not in ghost: ghost.append(rnd) if len(ghost)==2: return ghost print('GhostGame\n') door='__[ %s ]__' score, best_score, game = 0, 0, 1 doors = get_input('Enter the number of door[3..8] >> ', 3, 8) show_doors=''.join([door % i for i in range(1, doors+1)]) while True: print(show_doors) choice = get_input('Choose your door from 1 to %s >> ' % doors, 1, doors) ghost = get_ghost() print(get_msg('Ghost is here:\n', ghost, 'X')) print(get_msg('You is here:\n', [choice], 'O')) if choice in ghost: if score > best_score: best_score=score print('\n\nGame over.\nGame: %s. Your score: %s.' % (game, score)) s = input('Would you like to play again ? [Yes]/No >> ') if s.lower() in ['no', 'n']: break score=0 game+=1 else: score += 1 print('\n\nGame: %s. Score: %s.' % (game, score)) print('Games: %s. Best score: %s.' % (game, best_score))What do you think, about code?