String Repetition, online

Six activities your students do on their own devices. See who's finished, and their scores.

String Repetition in one minute

What students need to know

String * int repeats the string that many times. Great for drawing separator lines. Multiplying a string by 0 returns an empty string — perfectly valid.

* repeats the string — no spaces are added between repetitions. The string '-' is repeated 3 times with no gaps.

Mistakes students make

  • Line 2 uses x instead of *. Should be: line = "-" * 10.
  • Line 3 is missing quotes around -. Should be: separator = "-" * 15.
  • Line 2 puts the number in quotes. Use: line = "-" * 5.
  • Line 3 is missing *. Should be: dots = "." * 5.

Discover other journeys with this module

What students will learn in this module

Every question in Module 8

Quick questions

  1. What is "*" * 5?A* * * * *B*****
  2. What is "-" * 3?A---B- - -
  3. What is "Ha" * 3?AHaHaHaBHa Ha Ha
  4. What is "=" * 10?A= = = = = = = = = =B==========
  5. Does "*" * 5 add spaces?ANoBYes

Key terms

Students type the meaning of:

  • "*" * 10
  • "-" * 5
  • "Ha" * 3
  • "=" * 20

Match the pairs

'Ha' * 2.5Match it to what it does
'abc' * 'abc'Match it to what it does
line = '-' * 20Match it to what it does
'Ha' * 0Match it to what it does
print('Ha' * 3)Match it to what it does
print('*' * 5)Match it to what it does

Fill in the blanks

  1. line = "-" _ 20
    # Output: --------------------
  2. stars = ___ * 10
    # Output: **********
  3. border = "=" * __
    # Output: ===============
  4. laugh = "Ha" * _
    # Output: HaHaHa
  5. separator = 20 * ___
    # Output: --------------------

Spot the error

Question 1

Astars = "*" * 5Bline = "-" x 10Cprint(line)

Question 2

Aborder = "=" * 20Blaugh = "Ha" * 3Cseparator = - * 15Dprint(separator)

Question 3

Astars = "*" * 10Bline = "-" * "5"Cprint(line)

Question 4

Apattern = "ABC" * 3Bline = "-" * 20Cdots = "." 5Dprint(dots)

Question 5

Aborder1 = "#" * 10Bborder2 = 15 * "#"Claugh = Ha * 3Dprint(laugh)