#🔒 Related if/else

36 messages · Page 1 of 1 (latest)

civic steeple
#

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

pearl cargoBOT
#

@civic steeple

Python help channel opened

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.

civic steeple
#
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")
jagged canyon
#

follow this

civic steeple
#

Hm what do you mean?

jagged canyon
#

```py
...typing code like this makes it easier for others to read...
```

civic steeple
#

Ohk

jagged canyon
#

ok so you know the difference between a string and an integer?

civic steeple
#

Yeah

#

String is immutable

jagged canyon
#

as in, you know the difference between "2" and 2 right?

civic steeple
#

Yesh

#

Do I'll have to make it a string

jagged canyon
#
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

civic steeple
#

Oh I see

#

Now working after adding '' around 2

jagged canyon
#

so

#

there are actually 2 ways

civic steeple
#

Ty

#

Ok

jagged canyon
#

of solving this problem

#

can you think of the other way?

civic steeple
#

Nope

#

Removing ' from a input thing?

jagged canyon
#

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?

compact bough
#

You know also use
type()
For know what data type it is

lavish moss
pearl cargoBOT
#
Python help channel closed for inactivity

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.