estoy haciendo un ejercicio en el que según el número en el que se encuentre el loop debo mostrar una frase de cierta lista u otra. Por ejemplo digamos que vamos por 2, debo mostrar una frase de la lista de frases para los numeros que terminan en 2, si estamos en 20, sería de la lista de numeros que terminan en 0.
La cosa es que no se cómo hacer tal cosa, sé que está la opción de usar %, osea el resto de la división, pero hay números que son divisibles entre 2, 4, 6 u 8... Me mostraría la lista del 2.
Hice el programa con el % para ver si a partir de ahí se me ocurría algo, pero el output que obtengo es nada, simplemente me sale Process finished with exit code 0.
La verdad estoy un poco atascado y agradecería la ayuda, el código es un poco grande pero bueno jajaja.
import random
from time import sleep
REST_TIME = 1
happy_quotes = ["Every day is a new day.", "The purpose of our lives is to be happy.",
"Embrace the glorious mess that you are.",
"Being happy never goes out of style.",
"Happiness is the best makeup.",
"The mere sense of living is joy enough.",
"The only thing that will make you happy is being happy with who you are."]
furniture = ["Office chair", "Desk", "Bookshelf", "Table lamp", "Stool",
"Bench", "Sofa", "Armchair"]
drinks = ["Cola drink", "Coffe", "Chocolate", "Beer", "Wine", "Juice",
"Iced tea", "Water"]
hate_quotes = ["It is easy to hate and it is difficult to love.",
"From the deepest desires often come the deadliest hate."
"Hating people is like burning down your own house to get rid of a rat",
"Hate cages all the good things about you.",
"Hate is like water in a dry gulch. The longer it runs, the deeper it digs."]
foods = ["Chicken", "Fish", "Eggs", "Rice", "Peanut", "Tomato", "Bread", "Soup"
"Corn", "Meat" "Cookie", "Arepa", "Burger",
"Pizza", "Ice cream", "Beans"]
absurd_phrases = ["A First Sign of the Beginning of Understanding is the Wish to Die.",
"Religion. It's given people hope in a world torn apart by religion.",
"Beauty is a whore, I like money better",
"When all else fails, there's always delusion."]
animals = ["Dog", "Cat", "Bunny", "Kanguroo", "Bird", "Hamster", "Frog", "Horse"
"Parrot", "Goat", "Rat", "Snake", "Duck"]
motivational_quotes = ["Your limitation—it’s only your imagination.",
"Sometimes later becomes never. Do it now.",
"Dream it. Wish. Do it.",
"Dream bigger. Do bigger.",
"Do something today your future self will thank you for",
"Little things make big days."]
animal_sounds = ["Wof wof", "Kii-kiki-ri-ki", "Meow- meow", "Cuack-cuack", "Oink-oink",
"Moo-moo"]
sad_quotes = ["It's okay to be sad if things don't go the way you had hoped.",
"Everything takes me longer than I expect. It's the sad truth about life.",
"Tears are words that need to be writtin.",
"We must understand that sadness is an ocean, and sometimes we drown, while other days we are forced to"
"There is no greater sorrow than to recall in misery the time when we were happy."]
def choosefromlist(list_from):
print(random.choice(list_from))
sleep(REST_TIME)
def main():
time = 0
while True:
if time % 1 == 0:
choosefromlist(happy_quotes)
time += 1
elif time % 2 == 0:
choosefromlist(furniture)
time += 1
elif time % 3 == 0:
choosefromlist(drinks)
time += 1
elif time % 4 == 0:
choosefromlist(hate_quotes)
time += 1
elif time % 5 == 0:
choosefromlist(foods)
time += 1
elif time % 6 == 0:
choosefromlist(absurd_phrases)
time += 1
elif time % 7 == 0:
choosefromlist(animals)
time += 1
elif time % 8 == 0:
choosefromlist(motivational_quotes)
time += 1
elif time % 9 == 0:
choosefromlist(animal_sounds)
time += 1
if __name__ == "__main__":
main()
Aquí está el ejercicio por si ayuda en algo, muchas gracias de antemano.
"Escribe un programa que imprima por pantalla una frase aleatoria cada segundo. La lista de frases de la que se seleccionará la frase aleatoria será distinta según el segundo en el que estemos:
– Segundos acabados en ‘0’: frases alegres – Segundos acabados en ‘1’: nombres de muebles (silla, mesa) – Segundos acabados en ‘2’: nombres de bebidas – Segundos acabados en ‘3’: frases de odio – Segundos acabados en ‘4’: nombres de comidas – Segundos acabados en ‘5’: frases absurdas – Segundos acabados en ‘6’: nombres de animales – Segundos acabados en ‘7’: frases motivacionales – Segundos acabados en ‘8’: sonidos de animales – Segundos acabados en ‘9’: frases tristes "