-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_putar_angka.py
61 lines (54 loc) · 1.63 KB
/
menu_putar_angka.py
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
56
57
58
59
60
61
def listx(x):
y = []
for a in range (1,((x**2)+1)):
y.append(a)
return y
def normal(x):
z = ''
for loop1 in range (1,len(listx(x))+1):
z += ' {} '.format(loop1)
if loop1 % x == 0:
z += '\n'
return print(z)
def kebalik(x):
z = ''
for loop1 in range (len(listx(x)),0,-1):
z += ' {} '.format(loop1)
if (loop1+(x-1)) % x == 0:
z += '\n'
return print(z)
def putar_kanan(x):
z = ''
for b in range ((((x-1)*x)+1),(len(listx(x))+1)):
for a in range (x):
z += ' {} '.format(b-(x*a))
z += '\n'
return print(z)
def putar_kiri(x):
z = ''
for b in range (x,0,-1):
for a in range (x):
z += ' {} '.format(b+(x*a))
z += '\n'
print(z)
def mainmenu():
jalan = 'y'
while (jalan == 'y' ):
x = int(input('Masukkan ukuran = '))
normal(x)
putarx = input('Pilih putar ke kanan atau ke kiri = ').lower()
kalix = int(input('Pilih mau putar berapa kali = '))
if putarx == 'kanan' and kalix%4 == 1:
putar_kanan(x)
elif putarx == 'kanan' or putarx == 'kiri' and kalix%4 == 2:
kebalik(x)
elif putarx == 'kanan' and kalix%4 == 3:
putar_kiri(x)
elif putarx == 'kanan' or putarx == 'kiri' and kalix%4 == 0:
normal(x)
elif putarx == 'kiri' and kalix%4 == 1:
putar_kiri(x)
elif putarx == 'kiri' and kalix%4 == 3:
putar_kanan(x)
jalan = input('Main lagi ? (y/n) : ')
mainmenu()