How to Calculate (n+nn+nnn+nnnn) in Python


1. Introduction

In this example we will show how to calculate (n+nn+nn+nnnn) in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = input("Please input a number n = ")
n1 = n + n
n2 = n1 + n
n3 = n2 + n
sum = int(n) + int(n1) + int(n2) + int(n3)
print("{} + {} + {} + {} = {}".format(n, n1, n2, n3, sum))

Output:

Please input a number n = 3
3 + 33 + 333 + 3333 = 3702
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments