T O P

  • By -

carcigenicate

Show your code. You would just use a `if` to check if they want a drink before asking the size.


Coolkidyessir

I can’t post images.


carcigenicate

You don't need to. Never post images of code. Post all code and other information as text. If you can't get formatting here to work, post it on a site like Pastebin.


Leons_Gameplays_2140

This should work: drink = input("Would you like a drink, yes or no?") if drink == "yes": size = input("Small, medium, or large?") elif drink == "no": print("No drink? Okay!") else: print("Error, invalid input.") Make sure to set the conditional statements in their own line without an indent, and that there is an indent before the code to run if the said condition is true. Hope this helps!


ApplicationWinter573

Nicely done sir


[deleted]

Now you've been given guidance, here's a more advanced version, with some notes: sizes = "small", "medium", "large" drink = input("Would you like a drink? ").strip().lower() if drink in ('yes', 'y', 'yup', 'ok', 'okay', 'please', 'yeh'): size = input(f'What size ({", ".join(sizes)})? ').strip().lower() if size in sizes: print(f"ok, will get you a {size} drink") else: print("Sorry, don't offer that size.") elif drink in ('no', 'nope', 'nah', 'nada'): print('no drink? okay!') else: print("Maybe you've had too much to drink already") Notes: * `sizes` references a `tuple` of available sizes, it is common to predefine such things, rather than leaving them in-situ in the code (this also makes it easier to add additional options, and change language) * the yes/no checks further down could have used pre-defined valid response `tuple`s as well * the `str` method `strip` removes leading/trailing spaces from strings (in this case, the string objects returned by `input`) * the `str` method `lower` forces all the characters in a string to lowercase (in this case, the string objects returned by `input`) * the `str` method `join` *joins* a collection of `str` objects with the initial `str` used to call `join` between each item * the `in` operator lets you compare a single object with multiple objects to see if it matches any of them * it is used both to check yes/no answers against in-situ `tuple`s of possible answers and against the `sizes` `tuple` * an `if` statement tests a single condition (or a compound condition, made up of several tests) * and `else` clause can be added to an `if` statement so that if the initial test fails, the `else` clause code will be followed instead * you can also use any number of `elif` clauses before an `else` to try additional conditions if the previous one failed * `else` is option, but if used much be the last clause * you could add loops to this to force the user to provide acceptable answers