Я написал код своего вопроса, но все еще есть некоторые ошибки, и я не могу понять, как их решить. Пожалуйста, помогите ! ! 1
игра в Угадайку, в которой игрок должен угадать букву, случайно сгенерированную компьютером. Игрок имеет неограниченное количество догадок, и каждый раз, когда игрок делает предположение, компьютер будет предоставлять обратную связь о том, было ли предположение слишком высоким, слишком низким или правильным.
Любые предложения приветствуются
Что я уже пробовал:
# Guessing game # player guesses a random letter generated # unlimited guesses import random, string def main(): continue_game = True while continue_game== True: play_one_round() continue_game = play_again() def play_one_round(): # play one round of the game display_instructions() print('I am thinking of a letter between a and z.') # generate a random letter from a to z letter = random.choice(string.ascii_letters) letter = letter.lower() guess_num = 0 guess_list = [] overall_guess_list=[] while True: guess = input('Take a guess: ') guess_list.append(guess) guess_num = guess_num+1 if guess>= 'a' and guess<= 'z': if guess < letter: print('Your guess is too low.') continue elif guess > letter: print('Your guess is too high.') continue elif guess== letter: print('Good Job, you guessed the correct letter!') answer = guess break else: print('Invalid Input') continue print('---MY STATS---') print('Number of Guesses: ', guess_num) overall_guess_list.append(guess_num) # total guesses of all games ranking_label(guess_num) worst_letter = worst_guess(guess,answer, guess_list) print('Worst Letter Guess: ', worst_letter) play_again() def display_instructions(): # display instructions instructions_file = open('instructions.txt', 'r') instructions = instructions_file.read() instructions_file.close() print(instructions) def ranking_label(guess_num): if guess_num <5: print('Level: Expert') elif guess_num>=5 and guess_num<=10: print('Level: Intermediate') else: print('Level: Beginner') def worst_guess(guess, answer, guess_list): diff_list = [] for guess in guess_list: diff = abs(ord(guess)-ord(answer)) diff_list.append(diff) worst_num = int(max(diff_list)) worst_letter = abs(ord(answer)- worst_num) return chr(worst_letter) def play_again(): # prompt to play again # depends on player's choice again = input('Would you like to play again? Y/N ') if again.lower() == 'y': continue_game = True else: continue_game = False print(summary_stat(overall_guess_list)) return continue_game def summary_stat(overall_guess_list): print('---SUMMARY STATS---') lowest = min(overall_guess_list) highest = max(overall_guess_list) print('Lowest number of Guesses: ', lowest) print('Highest number of guesses: ', highest) avg_guess = sum(overall_guess_list)/ len(overall_guess_list) print('Average Number of Guesses: ', avg_guess) if avg_guess <5: print('Overall Level: Expert') elif avg_guess>=5 and avg_guess<=10: print('Overall Level: Intermediate') else: print('Overall Level: Beginner') main()
Richard MacCutchan
Я предлагаю вам задать вопрос.