Check Natural Number in Python

Beginner
⏱️ 9 min read
📚 Updated: May 2026
🎯 2 Code Examples
Integers

What you’ll learn

  • Natural number meaning in this page: integer greater than zero.
  • A reusable helper function for yes/no checking.
  • A range-print example and a live checker.

Overview

Under this tutorial rule, a number is natural if it is an integer and strictly positive.

Single check

One comparison: num > 0.

Range print

Second example prints 1 to 10.

Live preview

Type any integer and test instantly.

Prerequisites

Basic if conditions, loops, and integer values.

  • Understand comparisons like > and <=.
  • Know that integers do not include decimals.

The idea

Check only one condition: num > 0. If true, call it natural (under this page definition).

Zero and negative numbers are not natural here.

Live preview

Type an integer and check using the same rule as the code: n > 0.

Try 42, 0, and -3. Decimals will show an input warning.

Live result
Press "Check".

Algorithm

Goal: decide if integer num is natural using rule num > 0.

Take integer input

Use a fixed value or user input converted to int.

Check positivity

If num > 0, return true; else false.

Print message

Show whether it is natural under this definition.

📜 Pseudocode

Pseudocode
function is_natural(num):
    if num > 0:
        return true
    return false
1

Yes / no for one integer

Checks one integer and prints natural or not.

python
def is_natural(num: int) -> bool:
    return num > 0

def main() -> None:
    number = 42
    if is_natural(number):
        print(f"{number} is a natural number.")
    else:
        print(f"{number} is not a natural number.")

if __name__ == "__main__":
    main()
2

Print from 1 to 10 in order

Shows a basic range of natural numbers.

python
def print_integers_in_range(start: int, end: int) -> None:
    print(f"Natural numbers in the range {start} to {end}:")
    for i in range(start, end + 1):
        print(i, end=" ")
    print()

def main() -> None:
    start = 1
    end = 10
    print_integers_in_range(start, end)

if __name__ == "__main__":
    main()

Notes

Definition consistency. Keep your code rule and explanation aligned (especially for zero).

Input safety. Validate user input before converting to integer.

❓ FAQ

In this tutorial, natural means a positive integer: 1, 2, 3, and so on.
Depends on textbook definition. Here we use n > 0, so 0 is not natural in this page.
It keeps logic clean: helper decides yes/no, caller prints user-friendly message.
This page focuses on integers only. Values like 1.5 are not natural numbers.
They fail n > 0, so they are not natural under this definition.
One comparison is O(1). Printing a range from a to b is O(b-a+1).

🔄 Input / output

Examples use fixed values for clarity. You can replace with user input using int(input(...)).

Edge cases

Zero

n = 0

Not natural under this page rule (n > 0).

Input

Non-integer text

Validate and show a clear error message.

⏱️ Time and space complexity

OperationTimeExtra space
Single natural checkO(1)O(1)
Print range start..endO(end - start + 1)O(1)

Summary

  • Definition used: integer n where n > 0.
  • Patterns: one-value check and range listing.
  • Reminder: keep your code aligned with your syllabus definition for zero.
Did you know?

In many school texts, natural numbers start at 1 ({1, 2, 3, ...}). Some definitions include 0. This page uses the rule n > 0.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful