
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program for Print Number series without using any loop
In this article, we will learn about the solution to the problem statement given below −
Problem statement − Given Two number N and K, our problem is to subtract a number K from N until number(N) is greater than zero(0), once the N becomes negative or zero then we start adding K to it until that number become the original number(N).
For example,
N = 10 K = 4 Output will be: 10 6 2 -2 2 6 10
Algorithm
1. we call the function again and again until N is greater than zero (in every function call we subtract K from N ). 2. Once the number becomes negative or zero we start adding K in each function call until the number becomes the original number. 3. Here we used a single function for purpose of addition and subtraction but to switch between addition or subtraction function we used a Boolean type variable flag.
Now let’s observe the implementation in Python
Example
def PrintNumber(N, Original, K, flag): #print the number print(N, end = " ") #if number become negative if (N <= 0): if(flag==0): flag = 1 else: flag = 0 if (N == Original and (not(flag))): return # if flag is true if (flag == True): PrintNumber(N - K, Original, K, flag) return if (not(flag)): PrintNumber(N + K, Original, K, flag); return N = 10 K = 4 PrintNumber(N, N, K, True)
Output
10 6 2 -2 2 6 10
Here all variables are declared in global namespace as shown in the image below −
Conclusion
In this article, we learned about the terminology for printing a number series without using any kind of looping construct in Python 3.x. Or earlier.
- Related Articles
- Print Number series without using any loop in Python Program
- Java Program to print Number series without using any loop
- C program to print number series without using any loop
- Print m multiplies of n without using any loop in Python.
- Print first m multiples of n without using any loop in Python
- Print a pattern without using any loop in C++
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- Java program to print the fibonacci series of a given number using while loop
- Program to print numbers from 1 to 100 without using loop
- Python Program to Print Numbers in a Range (1,upper) Without Using any Loops
- Print a number 100 times without using loop, recursion and macro expansion in C
- C Program for Print the pattern by using one loop
- C program to print multiplication table by using for Loop
- C program to print name inside heart pattern using for loop.
- Python Program to Find the Fibonacci Series without Using Recursion

Advertisements