Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import os, sys
  2.  
  3. # Creates a class system for the program to pull out key words from each story
  4. # to prompt the user to input a word to fill in the blank
  5. class Item:
  6.    def __init__(self,type):
  7.       self._type=type
  8.       self._word=""
  9.    
  10.    def getType(self):
  11.       return self._type
  12.        
  13.    def setWord(self,word):
  14.       self_.word=word
  15.        
  16.    def getWord(self):
  17.       return self._word
  18.  
  19. # Open a file and list the contents
  20. path = "C:\\Users\\Morgan\\Desktop\\TextFiles\\"
  21. dirs = os.listdir( path )
  22.  
  23. # Numbers, and lists the stories from the directory
  24. i = 0
  25. for file in dirs:
  26.    print(str(i + 1) + ". " + file)
  27.    i = i + 1
  28.  
  29. # The minimum and maximum values for this program
  30. MIN_VALUE = 0
  31. MAX_VALUE = 9
  32.    
  33. # Prompts the user to select a story
  34. select_mlib = input(
  35.     'Enter a number between {} and {}: '.format( MIN_VALUE, MAX_VALUE )
  36. )
  37.    
  38. # Checks to see if the inputed number is a number
  39. (select_mlib.isdigit())
  40.    
  41. # Converts inputed number to an integer and assigns it to a variable
  42. selected = int(select_mlib)
  43.  
  44.  
  45.    
  46. # Checks to see if the integer is within the correct range
  47. if (selected > 10 ) or ( selected < 0):
  48.    print( ' Sorry, that number is to big or too small, please choose another' )
  49.    sys.exit()
  50. # Opens files, and reads them for key words to prompt the user for an input of
  51. # a verb, adjective, or noun
  52. else:
  53.    fo = open("C:\\Users\\Morgan\\Desktop\\TextFiles\\" + \
  54.              dirs[selected], "r+")
  55.    lines = fo.readlines()
  56.    items=[]
  57.    items.append(Item("verb"))
  58.    items.append(Item("adjective"))
  59.    items.append(Item("noun"))
  60.    print(items)  
  61.    for line in lines:
  62.       if ("verb, adjective, noun") in lines:
  63.          item.setWord(input("Please enter a ",item.getType()," "))
  64.          print (lines)
  65.       else:
  66.          pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement