We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Introduction
- Python If-Else
- Discussions
Python If-Else
Python If-Else
Sort by
recency
|
4382 Discussions
|
Please Login in order to post a comment
n = int(input().strip()) if n%2!=0: print("Weird") # for getting the odd value else: if n%2==0: # for getting even value if n in range(2,6): # these are the if conditions which were asked later and hint was given as the range from 2 to 6 etc print("Not Weird") if n in range(6,21): print("Weird") if n>20: print("Not Weird")
Why did this fail:
the last condition shouldn't be else but elif n > 20. Get it?
i don't understand, why doesnt the "else" work to catch the last possible case which is n = even number that is more than 20 ?
Given an integer, , perform the following conditional actions:
If is odd, print Weird If is even and in the inclusive range of to , print Not Weird If is even and in the inclusive range of to , print Weird If is even and greater than , print Not Weird Input Format
A single line containing a positive integer, .
if n % 2 == 1 or 6<=n<=20: print("Weird") else: print("Not Weird")