1.
Adding two number
a = 15
b = 12
# Adding two numbers
res = a + b
print(res)
Find Maximum of two numbers in Python
Using max()
max() function is the most optimized solution for finding the maximum
among two or more values. It is widely used due to its simplicity,
performance and readability. Internally implemented in C, it offers the best
efficiency in real-world scenarios.
a=7
b=3
print(max(a, b))
Factorial of a Number - Python
Given an integer n, the task is to compute its factorial, i.e., the product of all
positive integers from 1 to n. Factorial is represented as n! and is
commonly used in mathematics, permutations and combinatorics. For
Example:
Input: n = 6
Output: 720
Explanation: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720
Let's explore different methods to find the factorial of a number in Python.
Using [Link]()
This method computes the factorial using Python’s built-
in factorial() function, which performs the entire calculation internally
without requiring loops or recursion in user code.
import math
n=6
print([Link](n))
Python Program to Check Armstrong Number
Last Updated : 11 Oct, 2025
Given a number x, determine whether given number is Armstrong number
or not. An Armstrong number is a number that is equal to the sum of its
own digits each raised to the power of the number of digits.
For example:
153 = 1³ + 5³ + 3³ = 153 (Armstrong number)
120 ≠ 1³ + 2³ + 0³ = 9 (Not an Armstrong number)
Let’s explore different methods to check Armstrong numbers one by one.
Mathematical Method (Most Optimal)
This is the fastest and most efficient way to check an Armstrong number.
It uses integer arithmetic only, avoiding any string conversion overhead.
num = int(input("Enter a number: "))
n = num
power = len(str(num))
total = 0
while n > 0:
digit = n % 10
total += digit ** power
n //= 10
if total == num:
print("Armstrong Number")
else:
print("Not an Armstrong Number")
output 153is arm strong