This is a Python Program to read a number n and compute n+nn+nnn.
The program takes a number n and computes n+nn+nnn.
1. Take the value of a element and store in a variable n.
2. Convert the integer into string and store it in another variable.
3. Add the string twice so the string gets concatenated and store it in another variable.
4. Then add the string thrice and assign the value to the third variable.
5. Convert the strings in the second and third variables into integers.
6. Add the values in all the integers.
7. Print the total value of the expression.
8. Exit.
Here is the source code of the Python Program to read a number n and compute n+nn+nnn. The program output is also shown below.
n=int(input("Enter a number n: ")) temp=str(n) t1=temp+temp t2=temp+temp+temp comp=n+int(t1)+int(t2) print("The value is:",comp)
1. User must first enter the value and store it in a variable n.
2. The integer is converted to string for concatenation of the value of n.
3. The string is then concatenated once and twice and stored in separate variables.
4. Later to find the total sum, the string is converted back to integer.
5. The total value of the expression is then printed.
Case 1: Enter a number n: 5 The value is: 615 Case 2: Enter a number n: 20 The value is: 204060
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Check Information Technology Books
- Apply for Python Internship
- Check Python Books
- Practice Programming MCQs
- Apply for Programming Internship