Skip to content

Instantly share code, notes, and snippets.

@brainyfarm
Created August 8, 2016 07:38
Show Gist options
  • Save brainyfarm/5d3e216f4366e778a0669e9b7107b86f to your computer and use it in GitHub Desktop.
Save brainyfarm/5d3e216f4366e778a0669e9b7107b86f to your computer and use it in GitHub Desktop.
FreeCodeCamp: Repeat a String (Python)
"""
Repeat a given string (first argument) num times (second argument).
Return an empty string if num is not a positive number.
"""
def repeat_string(string, num):
result = ""
if(num < 0):
return ""
else:
while(num >= 1):
result += string
num -= 1
return result
print repeat_string("abc", 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment