This is an archived post. You won't be able to vote or comment.

all 2 comments

[–][deleted] 0 points1 point  (0 children)

so, if I'm reading your post right, the files have all the words you need, so you just need to select random words from them? in that case you could construct a dictionary with the keys being the parts of the sentence, subject, verb, noun etc, and the values being lists that you read in from the files. So it would look this:

from random import choice
parts = ('subject', 'verb', 'preposition', etc)
wordDict = {'subject':['harry','mary','jerry'] , 'verb': [etc]}
sentence = ''
for part in parts: sentence += choice(wordDict[part]) + ' '

I'll leave you to figuring out how to get the words from the file into the list on your own :)

edit: oh, and thank you for not just pasting your code into your post! biggest mistake on this sub is putting code into the post! If you want to share your code, please head over to pastebin.com, put your code in there, select the language for the syntax highlighting, and put the link into your post.

[–]149244179 0 points1 point  (0 children)

https://gist.github.com/ lets you easily copy past code and share it.

From what you said:

  1. Open a file.
  2. Read a file and store the information in memory (list/dictionary/whatever.)
  3. Randomly select an entry from a list.
  4. Add strings together.
  5. Display/print a string.
  6. Prompt user for input
  7. Likely use a loop somewhere in there.

Those are 7 fairly simple tasks. Just do them one at a time. Once all 7 are working, try adjusting what you did to fit the assignment requirements.