I'm a beginner and was practicing if else conditionals but I'm facing a problem in the picture you can see if 2 it gonna show congratulations you will not be able to survive
And in the terminal I'm entering 2 but still it's not seeing if condition and directly showing else
#🔒 Related if/else
36 messages · Page 1 of 1 (latest)
@civic steeple
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Caves = "I was going in a jungle and found two cavés \n . I will need to choose one because its night \n and ill have to choose one location \n. Cave A have footprints of a animal \nand from Cave 2 Cooking smell is coming outside"
print(Caves)
a = (input('Enter your choice cave 1 or 2: '))
if(a == 2):
print("Congratulations! You are not gonna survive")
elif(a == 3):
print("You entered a no. which is not given , it must be 1 or 2")
elif(a == 0):
print("You entered a no. which is not given , it must be 1 or 2")
else:
print("Congratulations , you survived")
Here's code
follow this
Hm what do you mean?
```py
...typing code like this makes it easier for others to read...
```
Ohk
Done
ok so you know the difference between a string and an integer?
as in, you know the difference between "2" and 2 right?
print(f"{a=}") # a='2'
print(a==2) # False
if(a == 2):
print("Congratulations! You are not gonna survive")
i added some print statements to help you see what a is
from the user's input, right?
i.e. making it a number
you can do int("1") to give you 1
but note that int("not a number")will give you an error
but I digress, shall we consider your question answered?
You know also use
type()
For know what data type it is
you really don't need parenthesis around everything, just a few things there really needs the parenthesises
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.