Python program to right rotate n-numbers by 1 Last Updated : 07 Feb, 2023 Comments Improve Suggest changes 1 Likes Like Report Given a number n. The task is to print n-integers n-times (starting from 1) and right rotate the integers by after each iteration.Examples: Input: 6 Output : 1 2 3 4 5 6 2 3 4 5 6 1 3 4 5 6 1 2 4 5 6 1 2 3 5 6 1 2 3 4 6 1 2 3 4 5 Input : 3 Output : 1 2 3 2 3 1 3 1 2 Method 1: Below is the implementation. Python3 def print_pattern(n): for i in range(1, n+1, 1): for j in range(1, n+1, 1): # check that if index i is # equal to j if i == j: print(j, end=" ") # if index i is less than j if i <= j: for k in range(j+1, n+1, 1): print(k, end=" ") for p in range(1, j, 1): print(p, end=" ") # print new line print() # Driver's code print_pattern(3) Output1 2 3 2 3 1 3 1 2 Method 2: Using pop(),append() and loops Python3 def print_pattern(n): x = [] for i in range(1, n+1): x.append(i) print(i, end=" ") print() j = 0 while(j < n-1): a = x[0] x.pop(0) x.append(a) for k in x: print(k, end=" ") print() j += 1 print_pattern(6) Output1 2 3 4 5 6 2 3 4 5 6 1 3 4 5 6 1 2 4 5 6 1 2 3 5 6 1 2 3 4 6 1 2 3 4 5 Using modulus operator: In this approach, we are using the modulus operator and adding i to the loop variable j to get the current number in each iteration. The time complexity of this approach is O(n^2) as it requires two nested loops. The space complexity is O(1) as we are only using a few variables and not using any extra data structures. Python3 def print_pattern(n): for i in range(n): for j in range(n): print((j+i)%n+1, end=" ") print() # Driver's code print_pattern(6) #This code is contributed by Edula Vinay Kumar Reddy Output1 2 3 4 5 6 2 3 4 5 6 1 3 4 5 6 1 2 4 5 6 1 2 3 5 6 1 2 3 4 6 1 2 3 4 5 Create Quiz Comment K krishna_6431 Follow 1 Improve K krishna_6431 Follow 1 Improve Article Tags : Python Python Programs pattern-printing Python Pattern-printing Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like