Python script if-else statement doubt

0 votes

Can you please explain when I give input as 1, why I am not able to see any results for below code?

N = int(input("enter number:"))
if N%2 != 0:
    if N >=2 and N<=5:
        print (N, "Not Wired")
    elif N>=6 and N<=20:
        print(N," ->Wired")
    elif N>20:
        print(N," ->NotWired")
   else:
        print ("Wired")
May 23, 2019 in Python by Sanjeev
949 views

1 answer to this question.

0 votes

The reason for this is that the else loop is inside the 2nd if loop, due to which the condition for when the input is 1 is not getting checked. This code should work fine:

N = int(input("enter number:"))
if N%2 != 0:
    if N >=2 and N<=5:
        print (N, "Not Wired")
    elif N>=6 and N<=20:
        print(N," ->Wired")
    elif N>20:
        print(N," ->NotWired")
else:
    print ("Wired")

Related Faq

How to exit a Python script in an if statement?

answered May 23, 2019 by Rajan

Related Questions In Python

+1 vote
5 answers

how to exit a python script in an if statement

Instead of using the normal UTF-8 encoding, ...READ MORE

answered Jul 4, 2023 in Python by bodymist
• 140 points
355,416 views
+1 vote
7 answers
0 votes
1 answer

Replacements for switch statement in Python?

You could use a dictionary: def f(x): ...READ MORE

answered May 29, 2018 in Python by aryya
• 7,460 points
729 views
0 votes
1 answer

What is the Python equivalent for a case/switch statement?

if x == 'a':  # Do the ...READ MORE

answered Jul 26, 2018 in Python by Priyaj
• 58,020 points
959 views
0 votes
1 answer

How to use nested if else statement in python?

The working of nested if-else is similar ...READ MORE

answered Nov 19, 2018 in Python by Nabarupa
1,259 views
0 votes
1 answer

How to write inline if statement for print in Python?

Inline if-else expression must always contain the else ...READ MORE

answered Dec 4, 2018 in Python by Nymeria
• 3,560 points

edited Dec 6, 2018 by Nymeria 16,750 views
0 votes
1 answer

what is an else if statement in python?

if condition:    statement elif condition:     statement #this is how you use ...READ MORE

answered Mar 15, 2019 in Python by Waseem
• 4,540 points
832 views
0 votes
2 answers
0 votes
1 answer

what are nested if statements in python?

nested if statements are statements with more ...READ MORE

answered May 21, 2019 in Python by Mohammad
• 3,230 points
783 views
0 votes
1 answer

Python: Doubt regarding private access specifier

In Python, you don't write to other ...READ MORE

answered May 23, 2019 in Python by Jagan
719 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP