For loops

M. Lim
Intro to Programming
1 min readApr 30, 2018

→ Lab Assignment: “Eminem Challenge” on repl.it

Write a program that prints the following lyrics, using the least amount of code. Use for loops for the repetitive parts!

# Don’t print the line numbers; those are just there to help you.1   Hi!
2 My name is (what?)
3 My name is (who?)
4 My name is Slim Shady
5 Hi!
6 My name is (huh?)
7 My name is (what?)
8 My name is Slim Shady
9 Hi!
10 My name is (what?)
11 My name is (who?)
12 My name is Slim Shady
13 Hi!
14 My name is (huh?)
15 My name is (what?)
16 My name is Slim Shady

Start by identifying patterns.

  1. Repeating words
  2. Repeating sections (groups of lines)
  3. Is there a pattern to the words that come after “My name is ” ?

Start small.

Don’t try to write the whole program all at once! Start with printing just the first 4 lines, and then expand on it from there.

Remember — for loops let you run the same code over and over again, each time with a DIFFERENT value. So, which value will you change each time?

--

--