0

How do I fix this to provide me with an answer?

hungry = input("y or n") healthy = input('y or n') if hungry == "n" and healthy == "n": print("Not hungry.") elif hungry == "n" and healthy == "y": print("Not hungry.") elif hungry == "y" and healthy == "n": print("Getting some junk food.") elif hungry == "y" and healthy == "y": print("Getting a healthy meal.")

23rd Feb 2023, 2:57 PM
Kamil Roginski
Kamil Roginski - avatar
8 Réponses
+ 6
Kamil Roginski Your inputs must be one of "n" Or "y" Otherwise you get no output. Add else part at last as else: print( "invalid inputs") to see when input is others.
23rd Feb 2023, 3:47 PM
Jayakrishna 🇮🇳
+ 6
Kamil Roginski please give clear description what error / message you are encountered.
23rd Feb 2023, 3:06 PM
Lothar
Lothar - avatar
+ 2
Iam getting proper outputs expected. How you are trying? Can you save and share code link by your sample input? I tried with samples like : n n Output: Not hungry, along with input messages y or n y or n before i can see on screen. Try n y Output: Not hungry y n Output: Getting some junk food y y Getting a healthy meal What actually you can see on the output screen?
23rd Feb 2023, 5:21 PM
Jayakrishna 🇮🇳
+ 1
hungry = input("are you hungry, y or n \n") healthy = input("are you healthy, y or n \n") if....
24th Feb 2023, 1:49 PM
Jayakrishna 🇮🇳
+ 1
If I understand what you're asking, either type the question inside of the parentheses for input(), or write a print() statement above each input. Also, at the end of your input(), a good tip you can do is put .lower() at the end so it will lower case whatever the user inputs. Then, when you evaluate the conditions within your "if-elif-else" block, put .startswith() so it will capture anything they enter that starts with your character of choice. So in your case try using: hungry = input("Are you hungry? Yes or No? ").lower() if hungry.startswith("y") This way, whatever they enter will all be converted into lowercase, and the .startswith("y") will check if what was input it started with "y". So even if they put "yes", "YES", "yEs", "yrrsh", it will still count as "y". Hope that helps.
24th Feb 2023, 9:28 PM
Adrian
Adrian - avatar
0
I received no message at all. It should provide me with one of the four answers I implemented, correct?
23rd Feb 2023, 3:14 PM
Kamil Roginski
Kamil Roginski - avatar
0
How would the code look. I tried the “n” or “y” in its place still nothing.
23rd Feb 2023, 5:08 PM
Kamil Roginski
Kamil Roginski - avatar
0
How do i get it to ask me the question “are you hungry, y or n,” and based on the answer “y” and “n” i get relevant result.
24th Feb 2023, 1:42 PM
Kamil Roginski
Kamil Roginski - avatar