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
|
4475 Discussions
|
Please Login in order to post a comment
omgggg test3 and test7 were failing because I was using the & operator instead of and #yesimajavavictim
!/bin/python3
import math import os import random import re import sys
if name == 'main': n = int(input().strip())
if n % 2 == 1 : print("Weird")
elif (n>=2 and n<=5): print("Not Weird")
elif (n >=6 and n<=20): print("Weird")
else: print("Not Weird")
here is the code :
if n % 2 !=0: print("Weird") elif n % 2 ==0 and 220: print("Not Weird")
This code works because - there are two outputs 'Weird' and 'Not Weird'. If we notice closely the cases when it should be 'Weird' we see two conditions n should be odd or in range 6 to 20. we can combine these conditions via OR statement and rese of the cases will be 'Not Weird' if(n%2 != 0 or (n>=6 and n<=20)): print('Weird') else: print('Not Weird')