Number programs · Python Programs

These classic number programs teach loops, conditions and functions through small problems with a known answer. Every page has the problem statement, a clear solution, the output, an explanation step by step and variations to try.

All 10

Python Program to Check Even or Odd Number
To check if a number is even or odd in Python, test `number % 2 == 0`: a remainder of 0 means the number is even, anything else m…
Python Program to Check Prime Number
A prime number is a whole number greater than 1 that has no divisors other than 1 and itself; in Python you test it by trying div…
Python Program to Find Factorial of a Number
The factorial of n (written n!) is the product of all whole numbers from 1 to n, and in Python you can compute it with a loop, wi…
Python Program to Print the Fibonacci Series
The Fibonacci series starts with 0 and 1, and every next term is the sum of the previous two; in Python the simplest way to print…
Python Program to Check Armstrong Number
An Armstrong number equals the sum of its digits each raised to the power of the number of digits; for example `153 = 1^3 + 5^3 +…
Python Program to Find GCD of Two Numbers
The GCD (greatest common divisor, also called HCF) of two numbers is the largest number that divides both exactly; in Python use …
Python Program to Check Leap Year
A year is a leap year if it is divisible by 4, except century years, which must also be divisible by 400; in Python that is `year…
Python Program to Find the Sum of Digits of a Number
To find the sum of the digits of a number in Python, either convert it to a string and add each digit with `sum(int(d) for d in s…
Python Program to Print a Multiplication Table
To print a multiplication table in Python, loop `i` from 1 to 10 with `range(1, 11)` and print `n * i` for each step, for example…
Python FizzBuzz Program
FizzBuzz asks you to print the numbers 1 to 100, replacing multiples of 3 with `Fizz`, multiples of 5 with `Buzz` and multiples o…

Explore more

Python ReferencePython ComparisonsPython How-To GuidesPython Cheat SheetsPython glossaryPython tutorial