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

 Live Demo

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.

Updated on: 16-Apr-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements