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
|
3899 Discussions
|
Please Login in order to post a comment
The Python If-Else statement is a fundamental feature of the language, allowing developers to execute different blocks of code based on certain conditions. Tigerexch247 Login
if n%2 != 0: print("Weird") elif n%2 == 0 and n>2 and n<=5: print("Not Werid") elif n%2 == 0 and n>6 and n<=20: print("Weird") else: print("Not Weird")
if (n%2 == 0): if(n>=2 and n<=5): print("Not Weird") elif(n>=6 and n<=20): print("Weird") elif(n>20): print("Not Weird") else: print("Weird")
This works fine: def check_number(n): if n % 2 == 1: print("Weird") elif 2 <= n <= 5 or n > 20: print("Not Weird") elif 6 <= n <= 20: print("Weird")
if name == 'main': n = int(input().strip())
check_number(n)