Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (120 points)

How to print the numbers given below without using any conditional statements? The set of numbers: var=01120221011202210112.

1 Answer

0 votes
by (119k points)

Here is the easiest way to print the number 01120221011202210112 without using conditional statements:

a='1011'

b='2022'

s = a+b+a+b+a+b

s[1:-3]

Explanation: If you observe, 10112022 pattern is repeating through the variable, So, initialize a as '1011' and b as '2022'. Concat a+b three times. After that sub-string the result string from 2nd character until the last 3rd character. 

If you are interested to learn Python, I would recommend this Python Training course Intellipaat which has experienced instructors, the best curriculum, and projects.

Browse Categories

...