Given two integral numbers in string format, we have to define a function that can receive these numbers, convert into integers and return the sum as integer in Python.
Example:
Input:
num1 = "10"
num2 = "20"
Function calling:
calculateSum(num1, num2)
Output:
Sum = 30
Logic:
- Input two numbers in string format (We are just assigning the hard-coded values here), note that, numbers should be integral type.
- Define a function, pass these values as parameters.
- Explicitly convert the values to integer by using int(variable/value).
- Calculate the sum and return it.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer