Skip to Content
Learn
Strings & Console Output
String Formatting with %, Part 2

Remember, we used the % operator to replace the %s placeholders with the variables in parentheses.

name = "Mike" print "Hello %s" % (name)

You need the same number of %s terms in a string as the number of variables in parentheses:

print "The %s who %s %s!" % ("Knights", "say", "Ni") # This will print "The Knights who say Ni!"

Instructions

1.

Now it’s your turn! We have ___ in the code to show you what you need to change!

  1. Inside the string, replace the three ___ with %s.
  2. After the string but before the three variables, replace the final ___ with a %.
  3. Hit Run.
Folder Icon

Take this course for free

Already have an account?