-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeginner - Nested Loops (practice code series)
More file actions
55 lines (45 loc) · 1.18 KB
/
Beginner - Nested Loops (practice code series)
File metadata and controls
55 lines (45 loc) · 1.18 KB
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
46
47
48
49
50
51
52
53
54
55
task = input()
def permutation(s):
n = len(s)
for i in range(n):
for j in range(n):
if i != j:
print(s[i] + s[j])
def sorted_permutation(s):
n = len(s)
for i in range(n):
for j in range(n):
if i != j and s[i] < s[j]:
print(s[i] + s[j])
def repeat_the_repeat(n):
for i in range(1, n + 1):
for j in range(1, n + 1):
print(j, end='')
print()
def repeat_incrementally(n):
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end='')
print()
def increment_and_decrement(n):
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()
if task == "permutation":
s = input()
permutation(s)
elif task == "sorted_permutation":
s = input()
sorted_permutation(s)
elif task == "repeat_the_repeat":
n = int(input())
repeat_the_repeat(n)
elif task == "repeat_incrementally":
n = int(input())
repeat_incrementally(n)
elif task == "increment_and_decrement":
n = int(input())
increment_and_decrement(n)