# 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)