Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys
- # Creates a class system for the program to pull out key words from each story
- # to prompt the user to input a word to fill in the blank
- class Item:
- def __init__(self,type):
- self._type=type
- self._word=""
- def getType(self):
- return self._type
- def setWord(self,word):
- self_.word=word
- def getWord(self):
- return self._word
- # Open a file and list the contents
- path = "C:\\Users\\Morgan\\Desktop\\TextFiles\\"
- dirs = os.listdir( path )
- # Numbers, and lists the stories from the directory
- i = 0
- for file in dirs:
- print(str(i + 1) + ". " + file)
- i = i + 1
- # The minimum and maximum values for this program
- MIN_VALUE = 0
- MAX_VALUE = 9
- # Prompts the user to select a story
- select_mlib = input(
- 'Enter a number between {} and {}: '.format( MIN_VALUE, MAX_VALUE )
- )
- # Checks to see if the inputed number is a number
- (select_mlib.isdigit())
- # Converts inputed number to an integer and assigns it to a variable
- selected = int(select_mlib)
- # Checks to see if the integer is within the correct range
- if (selected > 10 ) or ( selected < 0):
- print( ' Sorry, that number is to big or too small, please choose another' )
- sys.exit()
- # Opens files, and reads them for key words to prompt the user for an input of
- # a verb, adjective, or noun
- else:
- fo = open("C:\\Users\\Morgan\\Desktop\\TextFiles\\" + \
- dirs[selected], "r+")
- lines = fo.readlines()
- items=[]
- items.append(Item("verb"))
- items.append(Item("adjective"))
- items.append(Item("noun"))
- print(items)
- for line in lines:
- if ("verb, adjective, noun") in lines:
- item.setWord(input("Please enter a ",item.getType()," "))
- print (lines)
- else:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement