0% found this document useful (0 votes)
10 views2 pages

Adding Two Number

The document provides Python code examples for adding two numbers, finding the maximum of two numbers using the max() function, and calculating the factorial of a number using math.factorial(). It also explains how to check if a number is an Armstrong number using a mathematical method. Each section includes sample code and explanations of the concepts involved.

Uploaded by

Rizwan Basha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Adding Two Number

The document provides Python code examples for adding two numbers, finding the maximum of two numbers using the max() function, and calculating the factorial of a number using math.factorial(). It also explains how to check if a number is an Armstrong number using a mathematical method. Each section includes sample code and explanations of the concepts involved.

Uploaded by

Rizwan Basha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like