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
Output
need an explanation for this answer? contact us directly to get an explanation for this answer