Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #! python3
  2. # madlibs.py
  3.  
  4. import shelve, sys
  5.  
  6. adjective = input('Enter an adjective:')
  7.  
  8. noun = input('Enter a noun:')
  9.  
  10. verb = input('Enter a verb:')
  11.  
  12. secondnoun = input('Enter a noun:')
  13.  
  14. textfile = open('C:\\MadLibs\\Text.txt', 'r')
  15.  
  16. textfile = textfile.read()
  17.  
  18. textfile = textfile.split()
  19.  
  20. def change(textfile):
  21. nouncount = 0
  22. for word in enumerate(textfile):
  23. if word == 'ADJECTIVE':
  24. word = adjective
  25. elif word == 'NOUN':
  26. if word == 0:
  27. nouncount += 1
  28. word = noun
  29. else:
  30. word = secondnoun
  31. elif word == 'VERB.':
  32. word = verb
  33. result = change(textfile)
  34. print(result)
  35. result = ' '.join(result)
  36.  
  37. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement