Quiz 2
Registry Synced

May 2026 - Python - Week 3 - GrPA 3 - Nested loops - GRADED

891 words
4 min read

Reading compass

Now · Problem Statement

GrPA 3 - Nested loops - GRADED

Course: May 2026 - Python
Week 3

Problem Statement

Change in eligibility criteria to write oppe1 exam: A1>=40/100 AND A2>=40/100 AND A3>=40/100 AND A4>=40/100
Create a multi-functional program that performs different tasks based on the user input. The program should support the following tasks:
Permutation (permutation): Given a string s, print all the possible two-letter permutations(without repitition) of the letters in the string.
Sorted Permutation (sorted_permutation): Given a string s, print all the possible two-letter permutations(without repetition) of the letters in the string where the first character comes before the second one in alphabetical order. The order in which the permutations are printed is same as the previous one (Type: Filtering).
Repeat the Repeat (repeat_the_repeat): Given a number n, print the numbers from 1 to n in the same line and repeat this n times.
Repeat Incrementally (repeat_incrementally): Given a number n, print a pattern where the k-th line contains the first k numbers and there are n lines in total. For example, if n is 4, the output should be:
Increment and Decrement (increment_and_decrement): Given a number n, print a pattern where the k-th line should have the numbers from 1 to k and then back down to 1. For example, if n is 4, the output should be:

Test Cases

Public Test Cases

Case 1

Input:
text
permutation
abc
Expected Output:
text
ab
ac
ba
bc
ca
cb
Actual Output:
text
ab
ac
ba
bc
ca
cb

Case 2

Input:
text
permutation
dog
Expected Output:
text
do
dg
od
og
gd
go
Actual Output:
text
do
dg
od
og
gd
go

Case 3

Input:
text
sorted_permutation
bca
Expected Output:
text
bc
ab
ac
Actual Output:
text
bc
ab
ac

Case 4

Input:
text
sorted_permutation
bad
Expected Output:
text
bd
ab
ad
Actual Output:
text
bd
ab
ad

Case 5

Input:
text
repeat_the_repeat
3
Expected Output:
text
123
123
123
Actual Output:
text
123
123
123

Case 6

Input:
text
repeat_the_repeat
4
Expected Output:
text
1234
1234
1234
1234
Actual Output:
text
1234
1234
1234
1234

Case 7

Input:
text
repeat_incrementally
4
Expected Output:
text
1
12
123
1234
Actual Output:
text
1
12
123
1234

Case 8

Input:
text
repeat_incrementally
5
Expected Output:
text
1
12
123
1234
12345
Actual Output:
text
1
12
123
1234
12345

Case 9

Input:
text
increment_and_decrement
3
Expected Output:
text
1
121
12321
Actual Output:
text
1
121
12321

Case 10

Input:
text
increment_and_decrement
4
Expected Output:
text
1
121
12321
1234321
Actual Output:
text
1
121
12321
1234321

Private Test Cases

Case 1

Input:
text
permutation
xyz
Expected Output:
text
xy
xz
yx
yz
zx
zy
Actual Output:
text
xy
xz
yx
yz
zx
zy

Case 2

Input:
text
permutation
hi
Expected Output:
text
hi
ih
Actual Output:
text
hi
ih

Case 3

Input:
text
sorted_permutation
cba
Expected Output:
text
bc
ac
ab
Actual Output:
text
bc
ac
ab

Case 4

Input:
text
sorted_permutation
adc
Expected Output:
text
ad
ac
cd
Actual Output:
text
ad
ac
cd

Case 5

Input:
text
repeat_the_repeat
2
Expected Output:
text
12
12
Actual Output:
text
12
12

Case 6

Input:
text
repeat_the_repeat
5
Expected Output:
text
12345
12345
12345
12345
12345
Actual Output:
text
12345
12345
12345
12345
12345

Case 7

Input:
text
repeat_incrementally
2
Expected Output:
text
1
12
Actual Output:
text
1
12

Case 8

Input:
text
repeat_incrementally
6
Expected Output:
text
1
12
123
1234
12345
123456
Actual Output:
text
1
12
123
1234
12345
123456

Case 9

Input:
text
increment_and_decrement
2
Expected Output:
text
1
121
Actual Output:
text
1
121

Case 10

Input:
text
increment_and_decrement
5
Expected Output:
text
1
121
12321
1234321
123454321
Actual Output:
text
1
121
12321
1234321
123454321

Official Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
task = input()
if task == 'permutation':
s = input()
for i in range(len(s)):
for j in range(len(s)):
if i != j:
print(s[i] + s[j])
elif task == 'sorted_permutation':
s = input()
for i in range(len(s)):
for j in range(len(s)):
if i != j and s[i] < s[j]:
print(s[i] + s[j])
elif task == 'repeat_the_repeat':
n = int(input())
for _ in range(n):
for i in range(1, n+1):
print(i, end='')
print()
elif task == 'repeat_incrementally':
n = int(input())
for i in range(1, n+1):
for j in range(1, i+1):
print(j, end='')
print()
elif task == 'increment_and_decrement':
n = int(input())
for i in range(1, n+1):
for j in range(1, i+1):
print(j, end='')
for j in range(i-1, 0, -1):
print(j, end='')
print()
else:
print("Invalid")
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.