Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Created Hangman game in Python #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Python/Python_Games/hangman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

#Hangman game

import random

# Initialization
fruit_list = [
'apple',
'banana',
'orange',
'mango',
'strawberry',
'watermelon',
'kiwi',
'peach',
'pear',
'papaya',
'grapes',
'pineapple',
'guava',
'blueberry',
'blackberry',
'raspberry',
'apricot']

choice = 'Y'

# Game Start
while choice == 'Y':
#Setup
fruit = random.choice(fruit_list)
lives = 5
temp = []
word = []

for i in fruit:
word.append(i)
temp.append('_')

print("\n\tHANGMAN!")

#Gameplay
while '_' in temp and lives!=0:
print() #newline
for i in temp:
print(i, end = ' ')
print("\t Lives:", lives, '\n')
l = input("Guess a letter: ").lower()

if l in word:
for i in range(0,len(word)):
if word[i] == l:
temp[i] = l
else:
lives -= 1

# Game End
if lives == 0:
print("\nGAME OVER!")
else:
print("\nYOU WIN!!!")
print("The word was", fruit.upper())

choice = input("\nPlay Again?(y/n) ").upper()