From 426f6df3a99b26871285bbdd960a0e52ca192e7f Mon Sep 17 00:00:00 2001 From: M Kalyani <52488637+Kalakalyani@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:26:40 +0530 Subject: [PATCH 1/3] Add files via upload --- hangman-game/hangman.py | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 hangman-game/hangman.py diff --git a/hangman-game/hangman.py b/hangman-game/hangman.py new file mode 100644 index 0000000..8d8767a --- /dev/null +++ b/hangman-game/hangman.py @@ -0,0 +1,63 @@ +import random +print("---------------------------------------------------HANGMAN---------------------------------------------------") +print("*************************************************************************************************************") +print("----------------------------------------------------Rules----------------------------------------------------") +print("You have to choose any content from the given list and a related word will be randomly asked.") +print("You have to guess the word correctly in given number of chances.") +print("*************************************************************************************************************") +print("Let's start playing!") +contents={1:['cat','frog','sheep','snake','turtle','rabbit','crocodile','giraffe','cow','horse','pig','penguin','tiger','duck','bat','fox','elephant','monkey','dog','donkey','zebra','deer','kangaroo'], +2:['cricket','basketball','baseball','badminton','soccer','cycling','weightlifting','football','hockey','archery','volleyball','golf','javelin','tennis','running','surfing','darts','longjump','skiing'], +3:['bike','car','scooter','boat','van','rocket','bus','truck','ambulance','plane','train','helicopter','tractor','motorbike','auto'], +4:['policeman','nurse','mechanic','doctor','artist','pilot','driver','carpenter','scientist','reporter','teacher','farmer','electrician','builder','engineer','chef','pharmacist','soldier','plumber'], +5:['sun','rainbow','river','volcano','moon','flower','snow','bush','planet','rain','clouds','mountain','forest','cliffs','tree','leaf','desert','lake','wind','stars','island','tornado','earth'], +6:['violin','keyboard','saxophone','trumpet','clarinet','piano','drums','guitar','accordion','tambourine','harp','harmonica','banjo'], +7:['apartment','bridge','theatre','garage','petstore','hospital','skyscrapers','church','castle','airport','tunnel','stadium','factory','zoo','house','lighthouse'], +8:['red','yellow','black','orange','purple','blue','green','white','grey','brown'], +9:['india','america','australia','canada','ireland','southafrica','france','england','spain','thailand','egypt','china','italy','turkey','argentina','russia','germany','japan','brazil','mexico'], +10:['candle','magnet','satchel','dice','padlock','letter','microscope','balloon','briefcase','globe','can','sword','coins','box','luggage','axe','bolt','ball','drone','medal','shield']} +while(True): + print("Choose any topic from the given list:") + print("1.Animals\t2.Sports\t3.Transport\t4.Jobs\t\t5.Nature\n6.Music\t\t7.Buildings\t8.Colors\t9.Countries\t10.Things") + ch=int(input("Enter a number of your choice: ")) + try: + l=contents[ch] + except: + print("Please enter valid choice:") + continue + word=random.choice(l) + lw=len(word) + lives=lw-1 + print("You have",lives,"lives to guess the correct word. Each incorrect guess will decrease one life.") + sec='_'*lw + g=[] #to store the list of already guessed characters + while(lives!=0): + for s in sec: + print(s, end=" ") + w=list(word) + guess=(input("\nGuess a letter: ")).lower() + if guess in g: + print("You have already guessed the letter. Try something else!") + continue + g.append(guess) + if guess in word: + for i in range(len(w)): + if(w[i]==guess): + pos=i + s1=list(sec) + s1[pos]=guess + sec="".join(s1) + if(sec.find('_')==-1): + print("\nYou guessed the correct word!") + break + else: + lives-=1 + if(lives!=0): + print("You have {0} lives left, try again!".format(lives)) + else: + print("You lost!") + print("The correct word is: ",word) + print("\n1.Play again\t\t2.Quit") + pa=int(input("-->")) + if pa!=1: + break \ No newline at end of file From f5253556a16e267e781cfc5ce6ff42acec626d8a Mon Sep 17 00:00:00 2001 From: M Kalyani <52488637+Kalakalyani@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:33:45 +0530 Subject: [PATCH 2/3] Rename hangman.py to batch-1-hangman.py --- hangman-game/{hangman.py => batch-1-hangman.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename hangman-game/{hangman.py => batch-1-hangman.py} (98%) diff --git a/hangman-game/hangman.py b/hangman-game/batch-1-hangman.py similarity index 98% rename from hangman-game/hangman.py rename to hangman-game/batch-1-hangman.py index 8d8767a..fbaec31 100644 --- a/hangman-game/hangman.py +++ b/hangman-game/batch-1-hangman.py @@ -60,4 +60,4 @@ print("\n1.Play again\t\t2.Quit") pa=int(input("-->")) if pa!=1: - break \ No newline at end of file + break From 3c3f03ba0f41473b5bf0bb99fa75446afdcb1e0e Mon Sep 17 00:00:00 2001 From: M Kalyani <52488637+Kalakalyani@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:38:52 +0530 Subject: [PATCH 3/3] Update batch-1-hangman.py --- hangman-game/batch-1-hangman.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hangman-game/batch-1-hangman.py b/hangman-game/batch-1-hangman.py index fbaec31..26498c1 100644 --- a/hangman-game/batch-1-hangman.py +++ b/hangman-game/batch-1-hangman.py @@ -48,7 +48,7 @@ s1[pos]=guess sec="".join(s1) if(sec.find('_')==-1): - print("\nYou guessed the correct word!") + print("\nYou guessed the correct word!. Its",word) break else: lives-=1 @@ -56,7 +56,7 @@ print("You have {0} lives left, try again!".format(lives)) else: print("You lost!") - print("The correct word is: ",word) + print("The correct word is:",word) print("\n1.Play again\t\t2.Quit") pa=int(input("-->")) if pa!=1: