Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! usr/bin/env #python3
- # madLib.py - Create a program that creates a mad-lib.
- import os
- import re
- # Import a file with the base script, create a regex to find parts of speech.
- madLibFile = open('/Users/matthewtaggett/Desktop/python/madLibs')
- madLibContent = madLibFile.read()
- madFindRegex = re.compile(r'(NOUN|ADJECTIVE)', re.DOTALL)
- newMadLib = list(madFindRegex.findall(madLibContent))
- # Use the regex to find the parts of speech, then replace them with the new part of speech provided.
- for pos in str(newMadLib):
- print('What is a ' + pos)
- newpos = input()
- newMadLib = newMadLib.replace(newpos, pos)
- print(newMadLib)
- madLibFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement