Advertisement
Flaunchy

MadLib

Feb 9th, 2016
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #! usr/bin/env #python3
  2. # madLib.py - Create a program that creates a mad-lib.
  3.  
  4. import os
  5. import re
  6.  
  7. # Import a file with the base script, create a regex to find parts of speech.
  8.  
  9. madLibFile = open('/Users/matthewtaggett/Desktop/python/madLibs')
  10. madLibContent = madLibFile.read()
  11. madFindRegex = re.compile(r'(NOUN|ADJECTIVE)', re.DOTALL)
  12. newMadLib = list(madFindRegex.findall(madLibContent))
  13.  
  14.  
  15. # Use the regex to find the parts of speech, then replace them with the new part of speech provided.
  16.  
  17. for pos in str(newMadLib):
  18.         print('What is a ' + pos)
  19.         newpos = input()
  20.         newMadLib = newMadLib.replace(newpos, pos)
  21.  
  22. print(newMadLib)
  23.  
  24. madLibFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement