Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet76/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   72   73   74   75   76   77   78   79   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Adding Guessed Letters


Let’s now add the functionality to append the user’s guess to our guesses list:

37| print("Incorrect, ◻◻◻ 39| if ans not in guessed:
40|| guessed.append(ans) # add ans to guessed list
42| if lives <= 0: ◻◻◻

Go ahead and run the cell. Now the guesses list will update as the user plays the game.
ChApter 4 LIsts And Loops

Handling Previous Guesses


The very last order of business is making sure that when they guess the same letter again, that they don’t have a life taken away, but rather they are alerted that it’s been guessed. We’ll need to rewrite the entire conditional statement for checking if the letter is in the word though:

27|| game_over = True ◻◻◻
28| elif ans in word and ans not in guessed:
29|| print("You guessed correctly!") ◻◻◻
34| guesses[ i ] = ans ◻◻◻ 35| elif ans in guessed:
36|| print("You already guessed that. Try again.")
37| else: ◻◻◻

Go ahead and run the cell. We had to change the elif statement for line 28 because we also needed to check that the letter was not added to the guessed list yet. On line 35 we add a second elif statement that will check if the letter is specifically in the guessed list. Remember that once an if/elif statement runs, the following statements will not. If neither of those conditionals are True, then it means that they haven’t guessed the letter yet, and it’s not in the random word. The game is now complete with full functionality.

Final Output


Congratulations on completing this project! Due to the size of the project, the full code will not be written here. Instead, you may find the completed version of the code where this book’s resource files are located on Github. You can find the link in the front of the book. All resource files for each week are located within that link. To find the specific code for this project, simply open or download the “Week_04.ipynb” file. If you ran into errors along the way, be sure to cross-reference your code with the code in this file and see where you may have gone wrong. The final code output for all future projects can also be found in the same location, so be sure to bookmark this page.
What a day! We were able to use the concept of looping, along with the power of lists to create a fun game. try adding your own flare, or breaking it, to understand further what may or may not work.
Weekly Summary
This was certainly one of the longer weeks, filled with a ton of information. Be sure to take some time to practice these concepts, either on your own or by completing the end of week exercises. We covered why lists are so important in Python and how to use them within our program. Also covered were the two loops that Python offers, for loops and while loops. Using loops, we can rerun code as many times as necessary, or to iterate over data collections like lists. If you feel overwhelmed with all the information, rest assured that we use loops and lists in everything that we do. This will give you a lot of practice and repetition.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   72   73   74   75   76   77   78   79   ...   200




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