Created
August 8, 2016 07:38
-
-
Save brainyfarm/5d3e216f4366e778a0669e9b7107b86f to your computer and use it in GitHub Desktop.
FreeCodeCamp: Repeat a String (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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