- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to check a number n is weird or not
Suppose we have a number n. We shall have to check whether n is weird or not. Here a number is weird when − 1. The number is odd 2. The number is not in range 2 to 5 3. The number is even and in range 6 to 20
So, if the input is like n = 18, then the output will be Weird because it is even and in range 6 to 20.
To solve this, we will follow these steps −
- if n is odd, then
- return "Weird"
- otherwise when (n > 1 and n < 6) or n > 20, then
- return "Not Weird"
- otherwise when n > 6 and n < 21, then
- return "Weird"
Example
Let us see the following implementation to get better understanding −
def solve(n): if n & 1: return "Weird" elif (n > 1 and n < 6) or n > 20: return "Not Weird" elif n > 6 and n < 21: return "Weird" n = 18 print(solve(n))
Input
18
Output
Weird
- Related Articles
- Program to check a number is ugly number or not in Python
- Python program to check if a number is Prime or not
- Check whether N is a Dihedral Prime Number or not in Python
- Python program to check credit card number is valid or not
- Program to check a number is power of two or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Program to check whether a board is valid N queens solution or not in python
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C# Program to check if a number is prime or not
- C Program to Check Whether a Number is Prime or not?
- PHP program to check if a number is prime or not
- Java Program to Check Whether a Number is Prime or Not
- Python program to check a sentence is a pangrams or not.
- Program to check whether a number is Proth number or not in C++

Advertisements