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
225 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")
answered May 23, 2019 by Rajan

Related Questions In Python

0 votes
3 answers

how to exit a python script in an if statement

In Python, the break statement provides you with the opportunity ...READ MORE

answered Dec 13, 2020 in Python by Roshni
• 10,440 points
72,699 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,440 points
113 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,120 points
387 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
277 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,520 points

edited Dec 6, 2018 by Nymeria 12,856 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
165 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 20, 2019 in Python by Mohammad
• 3,230 points
105 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
74 views