Python Development Course
Chapter
>
Level
Basic Operators
String Formats
Objective
Call out the chickens and count how many chickens there are around each coup using strings. A coup being the chicken houses seen in the map.
Walk to the darker X mark in the right side of the field and call out the chickens in the field by using the speak() function. Write the word âChirpâ multiplied by ten to sound out a chirping sound 10 times , like this: player.speak("Chirp" * 10) .
By calling them out, youâll make sure there are no chickens inside the coups. Count how many chickens are around each coup and store the numbers inside variables named: left_coup, right_coup.
After setting up the variables head for each of the 2 X marks in front of each coup and call out the number of chickens around each using the variables. Write the string of words "Right Coup has %d Chickens" , the %d is where the number of chickens is inserted. You follow this up by inputting the variable you wish to use in the text: % (right_coup). For example:
right_coup = 2 player.speak("Right Coup has %d Chickens" % (right_coup)) # This will print on screen âRight Coup has 2 Chickensâ
To clarify, letters placed in â â marks are referred to as strings , the use of % inside a string are used to insert outside values into the string. The % itself is part of the coding language, and indicator that outside code is being added. The code %dsignifies the value inserted is a number.
Count the correct number of chickens around the left and right coup then store those numbers in the variables left_coup and right_coup respectively. Walk to the X marks and use the speak() function along with the message provided to call out the numbers accordingly and complete the level.