Sum of last digits of two given numbers in python
View Discussion Show
Improve Article Save Article View Discussion Improve Article Save Article Given a positive integer N(at least contain two digits). The task is to write a Python program to add the first and last digit of the given number N. Examples: Input: N = 1247 Output: 8 Explanation: First digit is 1 and Last digit is 7. So, addition of these two (1 + 7) is equal to 8. Input: N = 73 Output: 10 Method 1: String implementation
String Representation Python3
Output:
Method 2: Solve it using an integer
Python3
Output: Addition of first and last digit of the number is 8
Python Basic - 1: Exercise-33 with SolutionWrite a Python program to compute the digit number of sum of two given integers. Input: Pictorial Presentation: Sample Solution: Python Code:
Sample Output: Input two integers(a b): 5 7 Number of digit of a and b.: 2 Flowchart: Python Code Editor: Have another way to solve this solution? Contribute your code (and comments) through Disqus. Previous: Write a python program to find heights of the top three building in descending order from eight given buildings. How do you add last digit of two numbers in Python?“program to add first and last digit of a number in python” Code Answer. n = int(input("Enter any number : ")). number = str(n). first = int(number[0]). last = int(number[-1]). print(f"sum of {first} and {last} is : ",sum). How do you get the last digit of a number in Python?How to Get the Last Digit of a Decimal in Python. pi = 3.141.. last_digit = int(repr(pi)[-1]). print(f"The last digit of {pi} is {last_digit}"). How do you print the sum of the first and last elements in a list Python?Method 1: String implementation. Take input in the form of String or typecast given input in String.. Now pick the 0th index of the String and typecast it into Integer and store it in a variable.. The same thing with the -1st index and also store in another variable.. Now add these two variables and.. print them as an Output.. How do you sum numbers in Python?sum() function in Python
Python provides an inbuilt function sum() which sums up the numbers in the list. Syntax: sum(iterable, start) iterable : iterable can be anything list , tuples or dictionaries , but most importantly it should be numbers. start : this start is added to the sum of numbers in the iterable.
|