- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Input a Number n and Compute n+nn+nnn
When it is required to take a number and compute a specific pattern, the value of n is taken from the user. Next, two variables are assigned this specific pattern and their sum is calculated.
Below is a demonstration of the same −
Example
my_input = int(input("Enter a value for n...")) temp_val = str(my_input) t_1=temp_val+temp_val t_2=temp_val+temp_val+temp_val my_result = my_input+int(t_1)+int(t_2) print("The computed value is : ") print(my_result)
Output
Enter a value for n...4 The computed value is : 492
Explanation
An input from the user is taken.
It is converted into a string and assigned to a variable.
The value of ‘n*n’ and the value of ‘n*n*n’ is calculated.
Their sum is determined.
This sum is assigned to a variable.
This is displayed as the output.
Advertisements