From 4850a400492483b04e7d7372fd09082b73df2faf Mon Sep 17 00:00:00 2001 From: sergiomuse Date: Sun, 1 Aug 2021 01:08:01 -0500 Subject: [PATCH 1/3] Solve conflict --- Rock_Paper_Scissors.py | 44 +----------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/Rock_Paper_Scissors.py b/Rock_Paper_Scissors.py index 01280aa..099623c 100644 --- a/Rock_Paper_Scissors.py +++ b/Rock_Paper_Scissors.py @@ -1,12 +1,4 @@ -<<<<<<< HEAD import random -======= -<<<<<<< HEAD -import random -======= -#import random ->>>>>>> 66370bcc9858b510bd045c170f0ab235b988ef43 ->>>>>>> 1de2ca641e7641b5b791ce9850df5d986bfe70bf rock = ''' _______ ---' ____) @@ -33,7 +25,7 @@ (____) ---.__(___) ''' -<<<<<<< HEAD + game_images = [rock, paper, scissors] print("Welcome to game Rock, Paper or Scissor") print("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.") @@ -53,37 +45,3 @@ print(resultado) -======= - -print("Welcome to game rock, paper or scissors \n") -print("What do you choose? Type 0 for Rock, 1 for Paper, 2 for Scissors") - -player=int(input()) -print("Player") -if player == 0: - print(rock) -elif player == 1: - print(paper) -elif player == 2: - print(scissors) - -computer = random.randint(0, 2) - -print("Computer") -if computer == 0: - print(rock) -elif computer == 1: - print(paper) -elif computer == 2: - print(scissors) - -row1 = ["Draw","You lose","You win"] -row2 = ["You lose","Draw","You lose"] -row3 = ["You lose","You win","Draw"] -map = [row1, row2, row3] -print(player) -print(computer) -resultado = map [player][computer] - -print(resultado) ->>>>>>> 66370bcc9858b510bd045c170f0ab235b988ef43 From 88860603185f725caece960077bb25f3978dad9d Mon Sep 17 00:00:00 2001 From: sergiomuse Date: Thu, 5 Aug 2021 00:42:15 -0500 Subject: [PATCH 2/3] Hangman game with python using imports, lists, if and loops --- Hangman-Game/Hangman-Game.py | 105 +++++++++++++++++ Hangman-Game/hangman_art.py | 69 +++++++++++ Hangman-Game/hangman_words.py | 215 ++++++++++++++++++++++++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 Hangman-Game/Hangman-Game.py create mode 100644 Hangman-Game/hangman_art.py create mode 100644 Hangman-Game/hangman_words.py diff --git a/Hangman-Game/Hangman-Game.py b/Hangman-Game/Hangman-Game.py new file mode 100644 index 0000000..ff73cd5 --- /dev/null +++ b/Hangman-Game/Hangman-Game.py @@ -0,0 +1,105 @@ +import random + +stages = [''' + +---+ + | | + O | + /|\ | + / \ | + | +========= +''', ''' + +---+ + | | + O | + /|\ | + / | + | +========= +''', ''' + +---+ + | | + O | + /|\ | + | + | +========= +''', ''' + +---+ + | | + O | + /| | + | + | +=========''', ''' + +---+ + | | + O | + | | + | + | +========= +''', ''' + +---+ + | | + O | + | + | + | +========= +''', ''' + +---+ + | | + | + | + | + | +========= +'''] + +end_of_game = False +word_list = ["ardvark", "baboon", "camel"] +chosen_word = random.choice(word_list) +word_length = len(chosen_word) + +#TODO-1: - Create a variable called 'lives' to keep track of the number of lives left. +#Set 'lives' to equal 6. +lives = 6 + +#Testing code +print(f'Pssst, the solution is {chosen_word}.') + +#Create blanks +display = [] +for _ in range(word_length): + display += "_" + +while not end_of_game: + guess = input("Guess a letter: ").lower() + + #Check guessed letter + for position in range(word_length): + letter = chosen_word[position] + # print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}") + if letter == guess: + display[position] = letter + + #TODO-2: - If guess is not a letter in the chosen_word, + #Then reduce 'lives' by 1. + #If lives goes down to 0 then the game should stop and it should print "You lose." + if guess not in chosen_word: + lives -= 1 + if lives == 0: + end_of_game = True + print("You lose.") + + #Join all the elements in the list and turn it into a String. + print(f"{' '.join(display)}") + + #Check if user has got all letters. + if "_" not in display: + end_of_game = True + print("You win.") + + #TODO-3: - print the ASCII art from 'stages' that corresponds to the current number of 'lives' the user has remaining. + print(stages[lives]) diff --git a/Hangman-Game/hangman_art.py b/Hangman-Game/hangman_art.py new file mode 100644 index 0000000..0fa0592 --- /dev/null +++ b/Hangman-Game/hangman_art.py @@ -0,0 +1,69 @@ +stages = [''' + +---+ + | | + O | + /|\ | + / \ | + | +========= +''', ''' + +---+ + | | + O | + /|\ | + / | + | +========= +''', ''' + +---+ + | | + O | + /|\ | + | + | +========= +''', ''' + +---+ + | | + O | + /| | + | + | +=========''', ''' + +---+ + | | + O | + | | + | + | +========= +''', ''' + +---+ + | | + O | + | + | + | +========= +''', ''' + +---+ + | | + | + | + | + | +========= +'''] + +logo = ''' + _ +| | +| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __ +| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ +| | | | (_| | | | | (_| | | | | | | (_| | | | | +|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| + __/ | + |___/ ''' + + + \ No newline at end of file diff --git a/Hangman-Game/hangman_words.py b/Hangman-Game/hangman_words.py new file mode 100644 index 0000000..8cf8125 --- /dev/null +++ b/Hangman-Game/hangman_words.py @@ -0,0 +1,215 @@ +word_list = [ +'abruptly', +'absurd', +'abyss', +'affix', +'askew', +'avenue', +'awkward', +'axiom', +'azure', +'bagpipes', +'bandwagon', +'banjo', +'bayou', +'beekeeper', +'bikini', +'blitz', +'blizzard', +'boggle', +'bookworm', +'boxcar', +'boxful', +'buckaroo', +'buffalo', +'buffoon', +'buxom', +'buzzard', +'buzzing', +'buzzwords', +'caliph', +'cobweb', +'cockiness', +'croquet', +'crypt', +'curacao', +'cycle', +'daiquiri', +'dirndl', +'disavow', +'dizzying', +'duplex', +'dwarves', +'embezzle', +'equip', +'espionage', +'euouae', +'exodus', +'faking', +'fishhook', +'fixable', +'fjord', +'flapjack', +'flopping', +'fluffiness', +'flyby', +'foxglove', +'frazzled', +'frizzled', +'fuchsia', +'funny', +'gabby', +'galaxy', +'galvanize', +'gazebo', +'giaour', +'gizmo', +'glowworm', +'glyph', +'gnarly', +'gnostic', +'gossip', +'grogginess', +'haiku', +'haphazard', +'hyphen', +'iatrogenic', +'icebox', +'injury', +'ivory', +'ivy', +'jackpot', +'jaundice', +'jawbreaker', +'jaywalk', +'jazziest', +'jazzy', +'jelly', +'jigsaw', +'jinx', +'jiujitsu', +'jockey', +'jogging', +'joking', +'jovial', +'joyful', +'juicy', +'jukebox', +'jumbo', +'kayak', +'kazoo', +'keyhole', +'khaki', +'kilobyte', +'kiosk', +'kitsch', +'kiwifruit', +'klutz', +'knapsack', +'larynx', +'lengths', +'lucky', +'luxury', +'lymph', +'marquis', +'matrix', +'megahertz', +'microwave', +'mnemonic', +'mystify', +'naphtha', +'nightclub', +'nowadays', +'numbskull', +'nymph', +'onyx', +'ovary', +'oxidize', +'oxygen', +'pajama', +'peekaboo', +'phlegm', +'pixel', +'pizazz', +'pneumonia', +'polka', +'pshaw', +'psyche', +'puppy', +'puzzling', +'quartz', +'queue', +'quips', +'quixotic', +'quiz', +'quizzes', +'quorum', +'razzmatazz', +'rhubarb', +'rhythm', +'rickshaw', +'schnapps', +'scratch', +'shiv', +'snazzy', +'sphinx', +'spritz', +'squawk', +'staff', +'strength', +'strengths', +'stretch', +'stronghold', +'stymied', +'subway', +'swivel', +'syndrome', +'thriftless', +'thumbscrew', +'topaz', +'transcript', +'transgress', +'transplant', +'triphthong', +'twelfth', +'twelfths', +'unknown', +'unworthy', +'unzip', +'uptown', +'vaporize', +'vixen', +'vodka', +'voodoo', +'vortex', +'voyeurism', +'walkway', +'waltz', +'wave', +'wavy', +'waxy', +'wellspring', +'wheezy', +'whiskey', +'whizzing', +'whomever', +'wimpy', +'witchcraft', +'wizard', +'woozy', +'wristwatch', +'wyvern', +'xylophone', +'yachtsman', +'yippee', +'yoked', +'youthful', +'yummy', +'zephyr', +'zigzag', +'zigzagging', +'zilch', +'zipper', +'zodiac', +'zombie', +] \ No newline at end of file From 4d8afc5e816cef28e670c315a16bc31e20962dfd Mon Sep 17 00:00:00 2001 From: sergiomuse Date: Thu, 5 Aug 2021 00:44:52 -0500 Subject: [PATCH 3/3] Hangman game fix --- Hangman-Game/Hangman-Game.py | 102 +++++++---------------------------- 1 file changed, 20 insertions(+), 82 deletions(-) diff --git a/Hangman-Game/Hangman-Game.py b/Hangman-Game/Hangman-Game.py index ff73cd5..5109c3b 100644 --- a/Hangman-Game/Hangman-Game.py +++ b/Hangman-Game/Hangman-Game.py @@ -1,105 +1,43 @@ import random +from hangman_art import stages, logo +from hangman_words import word_list +from replit import clear -stages = [''' - +---+ - | | - O | - /|\ | - / \ | - | -========= -''', ''' - +---+ - | | - O | - /|\ | - / | - | -========= -''', ''' - +---+ - | | - O | - /|\ | - | - | -========= -''', ''' - +---+ - | | - O | - /| | - | - | -=========''', ''' - +---+ - | | - O | - | | - | - | -========= -''', ''' - +---+ - | | - O | - | - | - | -========= -''', ''' - +---+ - | | - | - | - | - | -========= -'''] +print(logo) +game_is_finished = False +lives = len(stages) - 1 -end_of_game = False -word_list = ["ardvark", "baboon", "camel"] chosen_word = random.choice(word_list) word_length = len(chosen_word) -#TODO-1: - Create a variable called 'lives' to keep track of the number of lives left. -#Set 'lives' to equal 6. -lives = 6 - -#Testing code -print(f'Pssst, the solution is {chosen_word}.') - -#Create blanks display = [] for _ in range(word_length): display += "_" -while not end_of_game: +while not game_is_finished: guess = input("Guess a letter: ").lower() - #Check guessed letter + #Use the clear() function imported from replit to clear the output between guesses. + clear() + + if guess in display: + print(f"You've already guessed {guess}") + for position in range(word_length): letter = chosen_word[position] - # print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}") if letter == guess: display[position] = letter + print(f"{' '.join(display)}") - #TODO-2: - If guess is not a letter in the chosen_word, - #Then reduce 'lives' by 1. - #If lives goes down to 0 then the game should stop and it should print "You lose." if guess not in chosen_word: + print(f"You guessed {guess}, that's not in the word. You lose a life.") lives -= 1 if lives == 0: - end_of_game = True + game_is_finished = True print("You lose.") - - #Join all the elements in the list and turn it into a String. - print(f"{' '.join(display)}") - - #Check if user has got all letters. - if "_" not in display: - end_of_game = True + + if not "_" in display: + game_is_finished = True print("You win.") - #TODO-3: - print the ASCII art from 'stages' that corresponds to the current number of 'lives' the user has remaining. - print(stages[lives]) + print(stages[lives]) \ No newline at end of file