0

I need help making my code work!

i need to make a magic 8 ball but can't figure out how to pull a random number 0-49 and pull a sentence from a string. I also want to make this happen when I press a button (making this on raspberry pi) or when I type fortune. if you need the list of answers let me know in the comments. I want to have this print to an LCD screen, if you could make it do that, that would be awesome here's what I have: x = randnum(0-49) XYZ = (put string selector here) print (XYZ)

15th Apr 2017, 1:59 PM
vortetty
vortetty - avatar
4 Respuestas
+ 8
import random x = random.randint(0, 49) XYZ = [] #your list here print (XYZ[x]) #or even better import random XYZ = [] #your list here print(random.sample(XYZ, 1) #Choose 1 random element from XYZ If you want to do it under certain input conditions, put it in appropriate if blocks
15th Apr 2017, 2:35 PM
Dinmukhamed Mailibay
Dinmukhamed Mailibay - avatar
+ 3
You can use dictionary, where each value is related to the key. Read more on lists or dictionaries here in Python course or in the Internet
7th May 2017, 6:21 AM
Dinmukhamed Mailibay
Dinmukhamed Mailibay - avatar
+ 1
how would I do the list? (as I am new to Python, I do not know much) also, I would like to be able to type "Fortune" and get a number. then once it pulls the number, match the number to a set sentence. example: say it picks 32, it would then go: 32 = hah, yeah right sucker! XYZ = 32 print (XYZ) then it would evaluate the value and print "hah, yeah right sucker!" or could I make the list have sentences and it chooses one of the sentences from the list? by the way I would need the library to to work for Python 3 idle, and if you can tell me, a way to put it into Python files so that I can use it in the Python command console. and thank you for the answer I am not very good with Python as I am just starting to use it.
6th May 2017, 5:57 PM
vortetty
vortetty - avatar
+ 1
ok.
7th May 2017, 3:45 PM
vortetty
vortetty - avatar