Advertisement
Ozzypig

Part 2 - Exercise 2 Solution

May 21st, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.51 KB | None | 0 0
  1. -- Problem: You have a little brother who is an annoying copycat.
  2. -- When you say a word, he'll repeat it once for every letter in
  3. -- the word. Hint: Use string.len(s)  to get the length of a string.
  4. -- Ex: string.len("Hello") will give 5. Given a word you've said,
  5. -- print what your brother would say.
  6. -- Solution: Print the word until a counter is equal to the length
  7. -- of the word.
  8. -- Input
  9. word = "code"
  10. counter = 0
  11. -- Output
  12. while counter < string.len(word) do
  13.     print(word)
  14.     counter = counter + 1
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement