![]() ![]() potionsonthewall = 10 numtotakedown = 1 hero.say(potionsonthewall + " potions of health on the wall!") # Sing the next line: hero.say(potionsonthewall + " potions of health!") # Sing the next line: hero.say("take " + numtotakedown + " down, pass it around!") potionsonthewall -= numtotakedown # Sing the last line: hero.say(potionsonthewall + " potions of health on the wall.")ħ 7 / klo #3. # Sing along, using string concatenation: # X potions of health on the wall! # X potions of health! # Take Y down, pass it around! # X-Y potions of health on the wall. potionsonthewall = 10 numtotakedown = 1 hero.say(potionsonthewall + " potions of health on the wall!") # Sing the next line: # Sing the next line: potionsonthewall -= numtotakedown # Sing the last line: You can concatenate (combine) strings with other strings, or numbers: numberofpotions = 5 hero.say("i have " + numberofpotions + " potions.") Use string concatenation to sing along with your friends! The song goes like this: potionsonthewall + " potions of health on the wall!" potionsonthewall + " potions of health!" "Take " + numtotakedown + " down, pass it around!" potionsonthewall + " potions of health on the wall."Ħ 6 / klo Deja Brew Ratkaisu # You can add strings together, and add numbers into strings. Deja Brew You can concatenate (combine) strings with other strings, or numbers: numberofpotions = 5 hero.say("i have " + numberofpotions + " potions.") Use string concatenation to sing along with your friends! # You can add strings together, and add numbers into strings. if enemy: hero.say("go away, " + enemy.id)ĥ 5 / klo #2. # Command the peasants to battle and the peons to go away! friend = hero.findnearestfriend() if friend: hero.say("to battle, " + friend.id + "!") # Now find the nearest enemy and tell them to go away. Friend and Foe Ratkaisu # Peasants and peons are gathering in the forest. Commanding peasants has be shown to you: hero.say("to battle, " + peasant.id + "!") # The above line makes the hero say something like: "To battle, Sally!" Please note, peons and peasants don't like it when you simply call their name! You need to add (or concatenate )Ĥ 4 / klo something to the strings to get them to act. ![]() ![]() In this level you will need to command peasants to battle and peons to go away by combining their id with another string. If you have two strings "foo" and "bar", what do you expect the result of "foo" + "bar" to be? It's very simple, in fact, as "foo" + "bar" is the same as "foobar"! It simply combines (or concatenates ) the two strings together. Just like numbers can be added together using +, strings also can make use of the + operator. You can also concatenate strings stored in variables: hero.say("to battle, " + peasant.id) # Peasants and peons are gathering in the forest. hero.say("to battle, " + "Sally!") This will cause your hero to say "To battle, Sally!". Friend and Foe You can combine two strings into one using the the + operator. Type " mlpdev" to enable cheat mode.1 1 / klo Computer Science 3 Python Introduces arithmetic, counters, advanced while loops, break, continue, arrays. While playing the game, press ~ to display the console window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |