The first thing is, I am "The Nube Exdordinare" and this help will be used to learn python, so in advance Thanks for any help!
I want to find a way to call on a specific value in a list when a certain word is used. Im trying to use the "index" method.
So let's say my program prints one random quote from the user's input, one "happy" the other "sad" is functional - But I am looking into the best quotes for the user input "word". So when the program prints "Type in your mood then hit enter: " and the user types in "sad" or "upset" the word sad or upset would reference a randomly picked quote from the sadMessages list.
I know there are two lists (sadMessages and happyMessages) for now. But I want to associate a users word using index to look for values in the list or even lists - randomly
My goal is to pull a value from a list due to user input like sad, happy, mad, silly...
There is a yes or no answer 8-Ball thing at the end - ignore it please (It's part of something Im going to tweak later.
The answer could be to make multiple lists and a bunch of "life" statements. (Just seems sloppy at best)
Thank you again to anyone that wants to help.
import random
happy= ["It is during our darkest moments that we must focus to see the light.",
"Tell me and I forget. Teach me and I remember. Involve me and I learn.",
"Do not go where the path may lead, go instead where there is no path and leave a trail.",
"You will face many defeats in life, but never let yourself be defeated.",
"The greatest glory in living lies not in never falling, but in rising every time we fall.",
"In the end, it's not the years in your life that count. It's the life in your years.",
"Never let the fear of striking out keep you from playing the game.",
"Life is either a daring adventure or nothing at all."]
sad= ["Dont cry because it’s over, smile because it happened.",
"Be yourself; everyone else is already taken",
"No one can make you feel inferior without your consent.",
"It’s not who you are that holds you back, its who you think you're not.",
"When you reach the end of your rope, tie a knot in it and hang on."]
print("please choose between happy or sad")#I want to change this to (In one word type how you feel.)
answer = input ()
if answer == "happy":
print("Check this out : " , random.choice(happy+sad))
elif answer == "sad":
print("This might help out : " , random.choice(sad))
messages = ['If I said no I would be wrong.',
'Yes, and go get a lottory ticket.',
'Oh Yes.',
'Could be no, or could be yes.',
'No. But ask again latter.',
'If you cair try to concentrate and ask again.',
'No way Jose, not this time, or mabye yes.',
'What is the airspeed of an unladen African swallow?',
'Very doutful. A Python program would never reveal this.'
'Opposite.',
'You need to read the Bible.'
'Leverage agile frameworks to provide a robust synopsis for high level overviews.']
while True:
question = input("Ask a Yes or No question? ")
if question:
print(messages[random.randint(0, len(messages) - 1)])
else:
break
Aucun commentaire:
Enregistrer un commentaire