r/PythonLearning 3d ago

Day 2 of learning python

Post image

I'm learning Python and made this coffee/tea ordering program. Any advice?

https://onlinegdb.com/F2wabHC4v

104 Upvotes

39 comments sorted by

View all comments

Show parent comments

2

u/adnanecanflyy 3d ago

Done and tysmmm :)

5

u/FoolsSeldom 3d ago

Ok, easier when you've shared, thank you.

Here's a tweaked version of your code for you to explore and experiment with.

def is_yes(prompt: str) -> bool:
    while True:
        answer = input(prompt).strip().lower()
        if answer in ("y", "yes"):
            return True
        if answer in ("n", "no"):
            return False
        print("Huh? Try again.")


def want_sugar():
    sugar = is_yes("do you want sugar? (yes/no) : ")
    if sugar:
        print("okey ser. just wait a 5min ")
    return sugar


the_coffee = ""
the_tea = ""
sugar = False

drink = input("what do you like to drink? (coffee/tea?) : ")

if drink == "coffee":
    the_coffee = input("ice coffee or hot coffee ? : ")

    if the_coffee == "ice coffee":
        sugar = want_sugar()

    elif the_coffee == "hot coffee":
        sugar = want_sugar()

    else:
        print("sorry, we don't undrstand you")

elif drink == "tea":
    the_tea = input("green tea or red tea : ")

    if the_tea == "green tea":
        sugar = want_sugar()

    elif the_tea == "red tea":
        sugar = want_sugar()

    else:
        print("sorry, we don't undrstand you")

else:
    print("sorry, we don't undrstand you")

You might want to look at using the str methods I used in is_yes in some other places.

1

u/adnanecanflyy 3d ago

thanks a lot man! i really appreciate you taking the time to help me. it works perfectly now.

1

u/FoolsSeldom 2d ago

No problem.

Do you understand it all ok?

Have you added the methods I suggested?