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.")
8 Respostas
+ 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.
+ 6
Kamil Roginski
please give clear description what error / message you are encountered.
+ 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?
+ 1
hungry = input("are you hungry, y or n \n")
healthy = input("are you healthy, y or n \n")
if....
+ 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.
0
I received no message at all. It should provide me with one of the four answers I implemented, correct?
0
How would the code look. I tried the ânâ or âyâ in its place still nothing.
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.