vendredi 22 février 2019

Input doesn't print out expected output in the Python Interpreter at the expected time

I'm trying to make a code that helps me choose a breakfast in easy and fast way. The options are based on how hungry I'm feeling and if I got a decent amount of time before leaving my house.

So, when I type in an expected input the interpreter should print out something at that exact moment. But the problem is that it isn't doing that. It is printing the expected output when the code is about to end.

I tried searching for possible answers but not a single one helped me. I also tried deleting the newer parts of my code to look for possible mistakes but got nothing.

I even tried rubber duck debugging with the little cat my family recently adopted :(.

Here is a picture of the PythonInterpreter: The first 3 words that are underlined are the expected input, and the string between brackets is the one that, for some reason, is printed out before the expected outputs

Here is my code (sorry if it looks like a mess):

fruta = ["Plátano", "Manzana", "Pera"]

ptiempo_yogurt = "Yogurt con cereal", "Yogurt solo"
mtiempo_yogurt = "Yogurt con avena cocida"
yogurt = [ptiempo_yogurt, mtiempo_yogurt]

ptiempo_bebi = ["Leche fría con punchao", "Leche fría con avena", "Leche fría con cereal", ptiempo_yogurt]
mtiempo_bebi = ["Té", "Agua hervida con punchao", "Leche caliente con avena", mtiempo_yogurt]
bebi = [ptiempo_bebi, mtiempo_bebi]

ptiempo_carbo = ["Tostadas (1-2)", "Un pan normal"]
mtiempo_carbo = ["Tostadas (1-3)", "Pan normal (1-2)", "Huevos duros (0-3)"]
carbo = [ptiempo_carbo, mtiempo_carbo]
#Carbo, Bebi, Yogurt and Fruta are just lists with strings

from time import sleep
def timecalentar():
    print("\n\nAntes de empezar con las comidas, si elegiste algún tipo de bebida caliente, te recomiendo irla calentando.")
#This function is supposed to work only if I have time to make a hot drink, giving me a brief time to choose my hot drink and recommending me to turn on the kettle.

ans_1 = input("¡Hey! Buenos días\n ¿Tienes mucha o poca hambre? Responde con Mucha o Poca. ")
#For now, it only works with "Mucha".
ans_avena = input("¿Por casualidad dejaste preparado algo la noche anterior? Responde con Sí o No. ")
#If it receives a "No" it deletes an specific element from a list. Elif, it doesn't do anything. Also, after receiving either of the expected inputs it prints out something (but for some reason it isn't printing it out at that time).
ans_2 = input("Por cierto, ¿tienes mucho o poco tiempo? Responde con Mucho o Poco. ")
#If it receives "Mucho" it changes the order of the lists. If it receives "Poco" shows me only the options that doesn't need a lot of time to be prepared. When either output is chosen it should say that I got a lot/little to no time and that I'm feeling really hungry/not that hungry. And then, it should print out the list of drinks that meet those requirements. (but for some reason it isn't printing it out at that time).
ans_huevo = input("Cierto. ¿Elegiste algún tipo de lácteo (leche o yogurt)? Responde con Sí o No. ")
#If it receives "Sí" it deletes an specific element from a list. Elif, it doesn't do anything. Also, unexpectedly this is printing out BEFORE the list of drinks.
print(ans_1)
print(ans_avena)
if ans_avena.lower() == "no":
    ptiempo_bebi = [phrase for phrase in ptiempo_bebi if "Leche fría con avena" not in phrase]
    print("Oh, okay.")
elif ans_avena.lower() == "sí":
    print("Oh, nice.")
else:
    print("Escribe bien.")
print(ans_2)
if ans_1.lower() == "mucha" or ans_1.lower() == "mucha hambre":
    if ans_2.lower() == "mucho" or ans_2.lower() == "mucho tiempo":
        print("Bien. Entonces tienes mucha hambre y tiempo.")
        bebi[0] = mtiempo_bebi
        bebi[1] = ptiempo_bebi
        carbo[0] = mtiempo_carbo
        carbo[1] = ptiempo_carbo
    elif ans_2.lower() == "poco" or ans_2.lower() == "poco tiempo":
        print("Ok. You are feeling hungry but are in a hurry.")
        del(bebi[1])
        del(carbo[1])
    print("Here's a list of drinks. ¿What do you want?\n\n" + str(bebi))
    if bebi[0] == mtiempo_bebi:
        sleep(10); timecalentar()
    print(ans_huevo) #For some reason this is printing out before its expected time.
    if ans_huevo.lower() == "sí":
        carbo = [phrase for phrase in mtiempo_carbo if "Huevos" not in phrase] #Deleting an specific item
    print("Bueno, aquí tienes las comidas. ¿Qué te gustaría?\n\n" + str(carbo))

I'd be really grateful if I could get a solution and an explanation, so I finally understand where I messed up.

Aucun commentaire:

Enregistrer un commentaire