Python Forum
Printing one thing from a list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Printing one thing from a list (/thread-15904.html)



Printing one thing from a list - bidoofis - Feb-05-2019

I'm trying to see if I can make something in Python that can make a sentence. The only way I can think to do this is by making the process go, "If I choose an 'I', than after that I should put (insert multiple things that would make sense to go after 'I' here)". Problem is I'm a noob at Python knowing next to nothing about how to use it. The most I could do is assign values and make it print out a math equation. I'm wondering if I can make it go like this:

print([One item from list A] [Item from list corresponding to the word from list A] [Item corresponding to that list]...) ect ect until a sentence is made.

Pry not the best way to do this but I thought it'd be a nice project.


RE: Printing one thing from a list - ichabod801 - Feb-05-2019

I would do it like MadLibs. A sentence with blanks in it, each blank having a part of speech (noun, verb, adjective). Then you have a list of nouns, a list of verbs, and a list of adjectives. Use random.choice to pick random words of the right parts of speech to fill in the blanks in the sentence.