def play_game(): attempts = 5 selected_word = random_word_generator.pick_random_word() current_word_state = "" for i in range(len(selected_word)): if selected_word[i] in ['a', 'e', 'i', 'o', 'u']: current_word_state += selected_word[i] else: current_word_state += '_' attempts_remaining = attempts print_current_state(current_word_state, attempts_remaining) while True: input_char = input("Guess a character: ") print("\n") current_word_state, attempts_remaining = input_character_in_word( selected_word, input_char, current_word_state, attempts_remaining) print_current_state(current_word_state, attempts_remaining) ended = check_game_status(selected_word, current_word_state, attempts_remaining) if ended: break
def play_game(attempts=5): """ Main logic of our program """ # generating a random word selected_word = random_word_generator.pick_random_word() # generating current state of the word current_word_state = "_" for i in range(len(selected_word)): if(selected_word) # attemps that are allowed attempts_remaining = attempts print_current_state(current_word_state,attempts_remaining) while True: input_char = input("Guess a charcter: ") print("") # check whether the input character is in selected word or not current_word_state, attempts_remaining = input_character_in_word(selected_word, input_char, current_word_state, attempts_remaining) print_current_state(current_word_state,attempts_remaining) game_ended = check_game_status(selected_word,current_word_state,attempts_remaining) if game_ended: break
def play_game(attempts=5): selected_word = pick_random_word() current_state = "" for i in selected_word: if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u': current_state += i else: current_state += '_' attempts_remaining = attempts print_current_state(current_state, attempts_remaining) while True: input_char = input("Guess the character : ") attempts_remaining, current_state = check_in_word( selected_word, input_char, attempts_remaining, current_state) print_current_state(current_state, attempts_remaining) check_game = check_the_game(selected_word, current_state, attempts_remaining) if check_game == False: break
def play_game(attempts=5): # It will contain main logic of my game # It will store the value of randomly picked word selected_word = pick_random_word() # It will show present status of the word current_word_state = "" for i in selected_word: if i == ' ' or i == 'a' or i == 'o' or i == 'e' or i == 'i' or i == 'u': current_word_state += i else: current_word_state += "_" attempts_remaining = attempts print_current_state(current_word_state, attempts_remaining) while True: input_char = input("Guess the character: ") print("") current_word_state, attempts_remaining = input_char_in_word( selected_word, input_char, current_word_state, attempts_remaining) print_current_state(current_word_state, attempts_remaining) game_end_checker = check_game_status(selected_word, current_word_state, attempts_remaining) if (game_end_checker == False): break
def play_game(): attempts = 5 selected_word = random_word_generator.pick_random_word() current_word_state = "" for i in range(len(selected_word)): if selected_word[i] == 'a' or selected_word[i] == 'e' or selected_word[ i] == 'i' or selected_word[i] == "o" or selected_word[i] == "u": current_word_state += selected_word[i] else: current_word_state += "_" attempts_remaining = attempts print_current_state(current_word_state, attempts) while True: input_char = input("Guess a character: ") print("\n") current_word_state, attempts_remaining = input_character_in_word( selected_word, input_char, current_word_state, attempts_remaining) print_current_state(current_word_state, attempts_remaining) game_ended = check_game_status(selected_word, current_word_state, attempts_remaining) if game_ended: break
def play_game(): selected_word = pick_random_word() current_state = "" for i in selected_word: if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u': current_state += i else: current_state += "_" attempts_left = 5 print_current_state(current_state, attempts_left) while True: input_char = input("Guess the character : ") current_state, attempts_left = check_state(input_char, attempts_left, selected_word, current_state) print_current_state(current_state, attempts_left) game_state = check_the_game(selected_word, current_state, attempts_left) if game_state: break
def main(): random_word = pick_random_word() current_word_state = "" attempt_remaining = 5 for i in random_word: if i in ['a', 'e', 'i', 'o', 'u']: current_word_state += i else: current_word_state += '_' flag = False while attempt_remaining > 0: print_current_word_state(current_word_state, attempt_remaining) char = input("Guess the character: ") current_word_state, attempt_remaining = check_char( random_word, char, current_word_state, attempt_remaining) if is_win(current_word_state, random_word): flag = True print("WINNER WINNER CHICHKEN DINNER!!!") break if not flag: print("You lost :)") print("random word was:", random_word)
def play_game(attempts=5): # "main logic of our program resides" # we are taking a random word here selected_word = random_word_generator.pick_random_word() #we are generating current word state current_word_state = "" for i in range(len(selected_word)): if selected_word[i] == 'a' or selected_word[i] == 'e' or selected_word[ i] == 'i' or selected_word[i] == 'o' or selected_word[i] == 'u': current_word_state += selected_word[i] else: current_word_state += "_" #we are creating a variable to check the number of attemots remaining attempts_remaining = attempts #we are going to use another function which will print the current state of the word print_current_state(current_word_state, attempts) while True: input_char = input("Guess the character: ") print("") current_word_state, attempts_remaining = input_character_in_word( selected_word, input_char, current_word_state, attempts_remaining) print_current_state(current_word_state, attempts_remaining) game_ended = check_game_status(selected_word, current_word_state, attempts_remaining) if game_ended: break
return current_state, attempt_remaining def check_game_status(random_word, current_state, attempt_remaining): if attempt_remaining <= 0: print("Sorry you lost") print("The word was", random_word) return True if current_state == random_word : print("congratulation you won") return True return False random_word = pick_random_word() current_state = "" for i in random_word: if i=='a' or i=='e' or i=='o' or i=='u' or i=='i': current_state += i else: current_state += "_" attempt_remaining = 5 print_current_state(current_state, attempt_remaining) while(True): input_char = input("Guess the character : ") current_state, attempt_remaining = check_state(input_char, attempt_remaining, random_word, current_state) print_current_state(current_state, attempt_remaining)
import sys sys.path.append('/home/gopesh/python/') import random_word_generator print(random_word_generator.pick_random_word())