-1

I tried taking an input from keyboard. the checking that input with an if else statement. But everytime the else part is working. The if statement does not happen to be true. I can't understand where I am going wrong.

Here is what I have done.

abc= raw_input("Enter a  2 digit number");
if abc==6:
    print "Its party time!!!"
else:
    print "Its work time"

Please suggest

0

3 Answers 3

1

Your input variable is a string. You need to cast it to an integer to correctly compare it to 6.

if int(abc) == 6:

Sign up to request clarification or add additional context in comments.

Comments

1

raw_input returns a string. abc is a string, and a string will never be equal with an integer. Try casting abc or the return value of raw_input(). Or, you can make 6 a string.

Casting the return value of raw_input() :

abc = int( raw_input('Enter a 2 digit number') )

Casting abc :

abc = int(abc)

or

if int(abc) == 6:

Changing 6 to string :

if abc == '6':

Comments

-1
>>> abc= raw_input("Enter a  2 digit number")
Enter a  2 digit number6
>>> if int(abc) == 6:
    print "Its party time!!!"


Its party time!!!
>>> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.