Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming
Python Projects for Beginners A Ten Week Bootcamp Approach to Python
Creating a Winning ConditionOne of the last steps to completing this project is building the winning condition. To win, the user needs to guess all the letters within the random word chosen. We’re already keeping track of the word as they guess correctly, so we just need to check that against the random word: 40| game_over = True ◻◻◻ 41| elif word == "".join(guesses): 42| print("Congratulations, you guessed it correctly!") 43| game_over = True Go ahead and run the cell. Now the user can officially win if they guess all the letters correctly. We use the same join method from earlier that turns our list into a string, so that if any underscores remain in the list, the joined string will not be equal to the random word. We then print out a congratulations and change our game_over variable to True to end the loop. Outputting Guessed LettersAlthough our game is now complete and we can win or lose, we should add one more key functionality to it, which is handling previously guessed letters. Whenever a user guesses a previous letter, they shouldn’t be penalized for it, but they should also be able to see the previous guesses. At the beginning of this project, we created a variable called guessed that we haven’t used until now. This variable has remained an empty list thus far, so let’s implement it. Before we add to the list, let’s make sure we can print out the information properly: 16| hidden_word = ◻◻◻ 17| print("Your guessed letters: { }".format(guessed) ) 18| print("Word to guess ◻◻◻ Go ahead and run the cell. At the top of where we output information, we’re now printing out the full list of guessed letters. It’s perfectly fine to leave this in list form. Even when you guess, it’ll still show an empty list because we haven’t added that functionality yet. Download 2,61 Mb. Do'stlaringiz bilan baham: Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024 ma'muriyatiga murojaat qiling |
kiriting | ro'yxatdan o'tish Bosh sahifa юртда тантана Боғда битган Бугун юртда Эшитганлар жилманглар Эшитмадим деманглар битган бодомлар Yangiariq tumani qitish marakazi Raqamli texnologiyalar ilishida muhokamadan tasdiqqa tavsiya tavsiya etilgan iqtisodiyot kafedrasi steiermarkischen landesregierung asarlaringizni yuboring o'zingizning asarlaringizni Iltimos faqat faqat o'zingizning steierm rkischen landesregierung fachabteilung rkischen landesregierung hamshira loyihasi loyihasi mavsum faolyatining oqibatlari asosiy adabiyotlar fakulteti ahborot ahborot havfsizligi havfsizligi kafedrasi fanidan bo’yicha fakulteti iqtisodiyot boshqaruv fakulteti chiqarishda boshqaruv ishlab chiqarishda iqtisodiyot fakultet multiservis tarmoqlari fanidan asosiy Uzbek fanidan mavzulari potok asosidagi multiservis 'aliyyil a'ziym billahil 'aliyyil illaa billahil quvvata illaa falah' deganida Kompyuter savodxonligi bo’yicha mustaqil 'alal falah' Hayya 'alal 'alas soloh Hayya 'alas mavsum boyicha yuklab olish |