Let's code a HANGMAN GAME in Python! 🕺

  Рет қаралды 21,379

Bro Code

Bro Code

Күн бұрын

Пікірлер: 40
@BroCodez
@BroCodez 5 ай бұрын
# Hangman in Python import random hangman_art = {0: (" ", " ", " "), 1: (" o ", " ", " "), 2: (" o ", " | ", " "), 3: (" o ", "/| ", " "), 4: (" o ", "/|\\", " "), 5: (" o ", "/|\\", "/ "), 6: (" o ", "/|\\", "/ \\")} words = ("aardvark", "alligator", "alpaca", "ant", "anteater", "antelope", "ape", "armadillo", "baboon", "badger", "bat", "bear", "beaver", "bee", "bison", "boar", "buffalo", "butterfly", "camel", "capybara", "caribou", "cat", "caterpillar", "cattle", "chamois", "cheetah", "chicken", "chimpanzee", "chinchilla", "chough", "clam", "cobra", "cockroach", "cod", "coyote", "crab", "crane", "crocodile", "crow", "curlew", "deer", "dinosaur", "dog", "dogfish", "dolphin", "donkey", "dormouse", "dotterel", "dove", "dragonfly", "duck", "dugong", "dunlin", "eagle", "echidna", "eel", "eland", "elephant", "elk", "emu", "falcon", "ferret", "finch", "fish", "flamingo", "fly", "fox", "frog", "gaur", "gazelle", "gerbil", "giraffe", "gnat", "gnu", "goat", "goldfinch", "goldfish", "goose", "gorilla", "goshawk", "grasshopper", "grouse", "guanaco", "gull", "hamster", "hare", "hawk", "hedgehog", "heron", "herring", "hippopotamus", "hornet", "horse", "human", "hummingbird", "hyena", "ibex", "ibis", "jackal", "jaguar", "jay", "jellyfish", "kangaroo", "kingfisher", "koala", "kookabura", "kouprey", "kudu", "lapwing", "lark", "lemur", "leopard", "lion", "llama", "lobster", "locust", "loris", "louse", "lyrebird", "magpie", "mallard", "manatee", "mandrill", "mantis", "marten", "meerkat", "mink", "mole", "mongoose", "monkey", "moose", "mosquito", "mouse", "mule", "narwhal", "newt", "nightingale", "octopus", "okapi", "opossum", "oryx", "ostrich", "otter", "owl", "ox", "oyster", "panda", "panther", "parrot", "partridge", "peafowl", "pelican", "penguin", "pheasant", "pig", "pigeon", "polar-bear", "pony", "porcupine", "porpoise", "quail", "quelea", "quetzal", "rabbit", "raccoon", "rail", "ram", "rat", "raven", "red-deer", "red-panda", "reindeer", "rhinoceros", "rook", "salamander", "salmon", "sand-dollar", "sandpiper", "sardine", "scorpion", "seahorse", "seal", "shark", "sheep", "shrew", "skunk", "snail", "snake", "sparrow", "spider", "spoonbill", "squid", "squirrel", "starling", "stingray", "stoat", "stork", "swallow", "swan", "tapir", "tarsier", "termite", "tiger", "toad", "trout", "turkey", "turtle", "viper", "vulture", "wallaby", "walrus", "wasp", "weasel", "whale", "wildcat", "wolf", "wolverine", "wombat", "woodcock", "woodpecker", "worm", "wren", "yak", "zebra") def display_man(wrong_guesses): print("**********") for line in hangman_art[wrong_guesses]: print(line) print("**********") def display_hint(hint): print(" ".join(hint)) def display_answer(answer): print(" ".join(answer)) def main(): answer = random.choice(words) hint = ["_"] * len(answer) wrong_guesses = 0 guessed_letters = set() is_running = True while is_running: display_man(wrong_guesses) display_hint(hint) guess = input("Enter a letter: ").lower() if len(guess) != 1 or not guess.isalpha(): print("Invalid input") continue if guess in guessed_letters: print(f"{guess} is already guessed") continue guessed_letters.add(guess) if guess in answer: for i in range(len(answer)): if answer[i] == guess: hint[i] = guess else: wrong_guesses += 1 if "_" not in hint: display_man(wrong_guesses) display_answer(answer) print("YOU WIN!") is_running = False elif wrong_guesses >= len(hangman_art) - 1: display_man(wrong_guesses) display_answer(answer) print("YOU LOSE!") is_running = False if ___name___ == "__main__": main()
@SGM_26
@SGM_26 5 ай бұрын
Thanks Bro
@Yih-s7j
@Yih-s7j 2 ай бұрын
Thank you so much!!
@ThatScripterConfiy
@ThatScripterConfiy 5 ай бұрын
im a big fan man! you are the best youtuber for python learning and much more i ever seen! i swear!
@SGM_26
@SGM_26 5 ай бұрын
Nice, was waiting for another game
@browtfareyou
@browtfareyou 4 ай бұрын
thanks bro, you are the goat python teacher 🐐🐐🐐
@reminderIknows
@reminderIknows 4 ай бұрын
when i first tried python, i made a hangman game on my own. and it worked much better than expected, everything was fully functional. goes to show that you can learn things easier when it's very similar to something else. (very similar to lua, my main language)
@Jjaewalker
@Jjaewalker 2 ай бұрын
This is literally what im doing now lmao I paused to watch this video
@spectrogames8
@spectrogames8 5 ай бұрын
I literally made this the day before and yours is completely different from mine
@Winner1vz
@Winner1vz Ай бұрын
same
@zohaibwaris-q8x
@zohaibwaris-q8x 3 ай бұрын
BRO WON THE GAME LIKE CRAZY FAST (GIGA CHAD)
@dysoneducation
@dysoneducation Ай бұрын
Bro is low-key the Best programming teacher in the world 🎉🎉😊
@Akash-wi4yz
@Akash-wi4yz 5 ай бұрын
Hey! Love your vids man. Can you do a Binary file vid next(I have doubts on writing multiple lines and accessing them). I have an exam on it in 2 days.
@hybridclasher123
@hybridclasher123 5 ай бұрын
I would love if you make a video on pytorch and neural networks in python.
@thebolt1806
@thebolt1806 5 ай бұрын
Can you please show us one capstone project as well
@nyashachamunokara9787
@nyashachamunokara9787 21 күн бұрын
Hey Bro! Awesome video as always! At 22:36 is there ever a situation whereby our wrong guesses can be greater than 6 and game still continues to play? If not: then should you not have used this code instead (at line 74): if wrong_guesses == 6:
@serjan534
@serjan534 4 ай бұрын
thank you sir. best teacher
@f1yEditssX
@f1yEditssX 5 ай бұрын
Why didnt this blow up yet
@kedarp8975
@kedarp8975 5 ай бұрын
Love u broo❤❤
@rzyrandol5848
@rzyrandol5848 4 ай бұрын
what editor do u use?
@kedarp8975
@kedarp8975 5 ай бұрын
Make guides on pandas too!!!
@sidnotthesloth1827
@sidnotthesloth1827 5 ай бұрын
Thanks bro!
@artificialintelligencebird
@artificialintelligencebird 5 ай бұрын
Love your videos! Can you make full course for Rust?
@MiguelNunes-t2s
@MiguelNunes-t2s 5 ай бұрын
Actually it's really good because I want to learn rust but I couldn't find a good video to learn rust, and this guy is the best at coding tutorials
@artificialintelligencebird
@artificialintelligencebird 5 ай бұрын
@@MiguelNunes-t2s same I want to learn Rust too
@johnm3229
@johnm3229 3 ай бұрын
10:31
@allennaik4434
@allennaik4434 5 ай бұрын
thanks Bro
@tadeucpii
@tadeucpii Ай бұрын
What if I wanted to make possible to vuess the full word?
@jimams_jamz5518
@jimams_jamz5518 3 ай бұрын
6:43
@jimams_jamz5518
@jimams_jamz5518 3 ай бұрын
10:16
@jimams_jamz5518
@jimams_jamz5518 3 ай бұрын
14:50
@SARVESHDevalekar
@SARVESHDevalekar 3 ай бұрын
My CODE: import random words = { "Lion": "Mammal", "Elephant": "Mammal", "Tiger": "Mammal", "Bear": "Mammal", "Giraffe": "Mammal", "Eagle": "Bird", "Parrot": "Bird", "Penguin": "Bird", "Sparrow": "Bird", "Owl": "Bird", "Snake": "Reptile", "Lizard": "Reptile", "Turtle": "Reptile", "Crocodile": "Reptile", "Chameleon": "Reptile", "Frog": "Amphibian", "Toad": "Amphibian", "Salamander": "Amphibian", "Newt": "Amphibian", "Salmon": "Fish", "Tuna": "Fish", "Goldfish": "Fish", "Shark": "Fish", "Clownfish": "Fish", "Butterfly": "Insect", "Ant": "Insect", "Beetle": "Insect", "Dragonfly": "Insect", "Spider": "Arachnid", "Scorpion": "Arachnid", "Tick": "Arachnid", "Harvestman": "Arachnid", "Daddy Longlegs": "Arachnid" } hangman_art={0:(" ", " ", " "), 1: (" o ", " ", " "), 2: (" o ", " | ", " "), 3: (" o ", "/| ", " "), 4: (" o ", "/|\\", " "), 5: (" o ", "/|\\", "/ "), 6: (" o ", "/|\\", "/ \\")} def disp_man(art,attemptNum): for i in art[attemptNum]: print(i) def disp_Blanks(blanks): print(" ".join(blanks)) count=0 ans_List=[] def check(guess,answer,blanks): global count global attemptNum global running global ans_List if guess=='quit': running=False elif guess in answer: for i in range(len(answer)): if answer[i]==guess: blanks[i]=guess ans_List.append(guess) count+=1 else: attemptNum+=1 print(f'Worng Guess...Try again') attemptNum=0 running=True def main(): global attemptNum global running global ans_List rmdPair=random.sample(list(words.items()),1) answer=rmdPair[0][0].lower() hint=rmdPair[0][1] blanks=['_'] * len(answer) while running: disp_man(hangman_art,attemptNum) print(f'Hint: {hint} ') disp_Blanks(blanks) guess=input('Enter the guess: ') if guess in ans_List: print(f'\'{guess}\' IS PREVIOUSLY USED... CANNOT USE AGAIN') attemptNum+=1 continue check(guess,answer,blanks) if len(ans_List)==len(answer): print(f'____CORRECT____') break elif attemptNum==6: disp_man(hangman_art,attemptNum) print(f'WRONG GUESSES.... ANSWER= {answer}') running=False if __name__=='__main__': main()
@zohaibwaris-q8x
@zohaibwaris-q8x 3 ай бұрын
I Played Your game It's good.
@ItsMyAntiDrug
@ItsMyAntiDrug 3 ай бұрын
I'm sure this is fun but mine is not working :_;
@WongKaiJun-n5y
@WongKaiJun-n5y 3 күн бұрын
goat
@EmilioAt77
@EmilioAt77 4 ай бұрын
Bro, you legend ❤️❤️
@Felipells2633
@Felipells2633 Ай бұрын
im doing this : import random words = ("apple", "orange", "banana", "pineapple", "coconut") #dictionary of key:() hangman_art = {0: (" " " " " "), 1: (" o " " " " "), 2: (" o " " | " " "), 3: (" o " "/| " " "), 4: (" o " "/|\\ " " "), 5: (" o " "/|\\" "/ "), 6: (" o " "/|\\" "/ \\")} for line in hangman_art[0]: print(line) but instead of printing like in the video is showing like this : o / |
@Felipells2633
@Felipells2633 Ай бұрын
my god i forget the , in each key thats why going to leave this here so i can remember my newbness
@KyriproShorts
@KyriproShorts 5 ай бұрын
Sure! Lets do it..... Wait why is it not working??? Error, Error, Error, Error.
Learn Python Object Oriented Programming! 🚗
12:18
Bro Code
Рет қаралды 33 М.
Let's code a beginner's Python SLOT MACHINE 🎰
20:11
Bro Code
Рет қаралды 31 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Can you fit a whole game into a QR code?
20:03
MattKC
Рет қаралды 9 МЛН
God-Tier Developer Roadmap
16:42
Fireship
Рет қаралды 7 МЛН
Solving Meta Interview Questions for 2 Hours Straight!!!
1:56:02
James Peralta
Рет қаралды 773
5 Good Python Habits
17:35
Indently
Рет қаралды 661 М.
Learn Python in 1 hour! 🐍 (2024)
1:00:00
Bro Code
Рет қаралды 182 М.
The World Depends on 60-Year-Old Code No One Knows Anymore
9:30
Coding with Dee
Рет қаралды 1 МЛН
5 Uncommon Python Features I Love
15:09
Indently
Рет қаралды 169 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,2 МЛН
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 161 М.
All 39 Python Keywords Explained
34:08
Indently
Рет қаралды 216 М.