Nivå och poängvärde: | A 120 |
---|---|
Kort beskrivning: | Vi skapar en funktion |
Vad vi lär oss: | Att skapa egna simpla funktioner. |
Frihet i implementationen: | Liten. Här följer man instruktionerna till punkt och pricka. |
Realism: | Låg. |
Utmaning: | Lätt, om man kan läsa innantill. |
Arbetsmängd: | Lätt. De flesta klarar sig på en eller två timmar. |
Vi fortsätter på "Hänga Gubbe"-spelet
Skapa ett nytt projekt och modulen hanging_man.py (eller fortsätt på det tidigare projektet).
while
börjar på samma indentationsnivå som variabelinitieringarna.
while guess != word_to_guess and guesses_left > 0: anropa funktionen choose och spara spelarens val om valet är 'q', så skriv ut: 'You ended the game.' gå ut ur funktionen om valet är 'i', så anropa funktionen instructions om valet är 'l', så be användaren ge en bokstav och spara den i variabeln guess: 'Give your guess:\n' skriv ut texten 'You guessed ' samt bokstaven spelaren gav om valet är 'w', så be användaren gissa ordet och spara det: 'Guess the word:\n' om gissningen inte är rätt, så subtrahera 1 från guesses_left-variabeln anropa funktionen draw_one_step och ge som parameter variabeln guesses_left om gissningen är rätt, så skriv ut: '\nCorrect guess!' annars anropa funktionen end_of_game
Options: l guess a letter w guess the word i instructions q quit Give your choise (l/w/i/q): i I'm thinking about a word and your task is to guess that word by giving letters. If you give a correct letter, all instances of the letter in the word, will be shown. If you give a wrong letter, you are one step closer to be hanging. Also, if you give a letter that has already been used, hanging is closer. Underscores in the word represent missing letters. If you think, that you know the word before the last guess is used, you can give it. When the picture is like following, your time has ended. +-----+ | | | O | /|\ | / \ +------- | XXXXXXXXXX Options: l guess a letter w guess the word i instructions q quit Give your choise (l/w/i/q): l Give your guess: s You guessed s XXXXXXXXXX Options: l guess a letter w guess the word i instructions q quit Give your choise (l/w/i/q): w Guess the word: horse XXXXXXXXX Options: l guess a letter w guess the word i instructions q quit Give your choise (l/w/i/q): w Guess the word: sunflower XXXXXXXXX Correct guess!Om spelet avslutades mitt i:
Options: l guess a letter w guess the word i instructions q quit Give your choise (l/w/i/q): q You ended the game.Om tio gissningar inte räcker
Guess the word: abracadabra X Options: l guess a letter w guess the word i instructions q quit Give your choise (l/w/i/q): w Guess the word: surprise You ran out of time.
Lämna in filen hanging_man.py i Goblin.