Home » Python » Python programs

# Python program to find sum of two numbers

Here, we are going to learn **how to find sum of two numbers in Python**? we input two numbers and will find their sum.

Submitted by **IncludeHelp**, on March 30, 2019

**Given two integer numbers and we have to find their sum in Python.**

In the given below example, we have two variables num1 and num2 and assigning them with the value 10 and 20, finding and printing the sum of the numbers. Later we are inputting two numbers from the input and assigning them num1 and num2.

**Note:** While inputting numbers from using input() function, we get string value, to convert string value to an integer value – we need to convert them into integer. To convert string to an integer, use int() function.

## ASCII value of character in Python

In python, to get an ASCII code of a character, we use ord() function. ord() accepts a character and returns the ASCII value of it.

**Example code:**

num1 = input("Enter first number: ") num2 = input("Enter second number: ") sum = int(num1) + int(num2)

**Example:**

Input: num1 = 10 num2 = 20 Finding sum: sum = num1 + num2 Output: 30

**Python code to find sum of two numbers**

# python program to find sum of # two numbers num1 = 10 num2 = 20 # finding sum sum = num1 + num2 # printing sum print("sum of ", num1, " and ", num2, " is = ", sum) # taking input from user num1 = input("Enter first number: ") num2 = input("Enter second number: ") # finding sum sum = int(num1) + int(num2) # printing sum print("sum of ", num1, " and ", num2, " is = ", sum)

**Output**

sum of 10 and 20 is = 30 Enter first number: 100 Enter second number: 200 sum of 100 and 200 is = 300

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.

Learn PCB Designing: PCB DESIGNING TUTORIAL