String Repetition, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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.
PREVIOUS · MODULE 7String Concatenation
YOU ARE HERE · MODULE 8String Repetition
NEXT · MODULE 9len() function
What students will learn in this module
Every question in Module 8
Quick questions
- What is
"*" * 5?A* * * * *B***** - What is
"-" * 3?A---B- - - - What is
"Ha" * 3?AHaHaHaBHa Ha Ha - What is
"=" * 10?A= = = = = = = = = =B========== - Does
"*" * 5add 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 doesline = '-' * 20Match it to what it does'Ha' * 0Match it to what it doesprint('Ha' * 3)Match it to what it doesprint('*' * 5)Match it to what it doesFill in the blanks
line = "-" _ 20 # Output: --------------------
stars = ___ * 10 # Output: **********
border = "=" * __ # Output: ===============
laugh = "Ha" * _ # Output: HaHaHa
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)
