Created
February 5, 2018 23:20
-
-
Save gabrielbissey/3638dab6b310124c6335b0fd787935f1 to your computer and use it in GitHub Desktop.
Madlib processor
This file contains 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
from random import randint | |
def random_verb(): | |
random_num = randint(0, 1) | |
if random_num == 0: | |
return "run" | |
else: | |
return "kayak" | |
def random_noun(): | |
random_num = randint(0,1) | |
if random_num == 0: | |
return "sofa" | |
else: | |
return "llama" | |
def process_madlib(string): | |
processed = '' | |
i = 0 | |
while i != len(string): | |
next_character = string[i] | |
if next_character == 'N': | |
processed = processed + random_noun() | |
if next_character == 'V': | |
processed = processed + random_verb() | |
else: | |
processed = processed + next_character | |
i += 1 | |
return processed | |
print process_madlib("N it feels good to V a gangster") | |
print process_madlib('Hello N, do you know how to V?') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment