diff --git a/4/4.17/mad_lib.py b/4/4.17/mad_lib.py new file mode 100644 index 0000000..228c743 --- /dev/null +++ b/4/4.17/mad_lib.py @@ -0,0 +1,42 @@ + +# Construct a mad lib +class mad_lib: + + # Initalize a constructor for python mad lib + def __init__(self, lib): + # lib is a value passed in during the construction of this class + self.text = lib + self.input = input().split() + + # Replace %text% with user input + if '%first_name%' in self.text: + self.text = self.text.replace('%first_name%', self.first_name()) + if '%location%' in self.text: + self.text = self.text.replace('%location%', self.location()) + if '%whole_number%' in self.text: + self.text = self.text.replace('%whole_number%', self.whole_number()) + if '%plural_noun%' in self.text: + self.text = self.text.replace('%plural_noun%', self.plural_noun()) + + + def first_name(self): + #return input("A first name: ") + return self.input.pop() + + def location(self): + #return input("A location: ") + return self.input.pop() + + def whole_number(self): + #return input("A whole number: ") + return self.input.pop() + + def plural_noun(self): + #return input("A plural noun: ") + return self.input.pop() + +if __name__ == '__main__': + # Construct a mad lib + md = mad_lib('%first_name% went to %location% to buy %whole_number% different types of %plural_noun%') + + print(md.text) diff --git a/4/4.17/main.py b/4/4.17/main.py new file mode 100644 index 0000000..f5891a3 --- /dev/null +++ b/4/4.17/main.py @@ -0,0 +1,8 @@ +from mad_lib import mad_lib + +while True: + md = mad_lib('Eating %whole_number% %plural_noun% a day keeps the doctor away.') + if 'quit' in md.text: + break + else: + print(md.text)