-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask05.py
More file actions
57 lines (44 loc) · 1.35 KB
/
task05.py
File metadata and controls
57 lines (44 loc) · 1.35 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
56
57
# import library python
from os import system, name
# kode warna
rt = '\033[0m'
yl = '\033[93m'
lc = '\033[96m'
gr = '\033[32m'
pu = '\033[35m'
lr = '\033[91m'
# fungsi clear terminal
def clear():
# jika os windows
if name == 'nt':
_ = system('cls')
# jika os mac / linux
else:
_ = system('clear')
# trigger clear terminal
clear()
# fungsi cek inputan user
def cek(inputan):
# inisiasi looping
valid = False
# meminta input dari user + mengecek apakah tipe inputan integer atau bukan
while not valid:
try:
masukan = int(input("\t{}[{}?{}] Masukkan nilai {} : {}" .format(rt,yl,rt,inputan,lc)))
valid = True
except ValueError:
print("\t{}[{}!{}] Hanya menerima input bilangan bulat! silahkan ulangi!" .format(rt,lr,rt))
# mengembalikan nilai masukan
return masukan
# dekorasi
print("\n\t{}------------------------{} Input Data {}-------------------------\n" .format(pu,rt,pu))
# meminta input dari user lewat fungsi cek
x = cek("x")
y = cek("y")
z = cek("z")
# dekorasi
print("\n\t{}-----------------------{} Output Data {}-------------------------" .format(pu,rt,pu))
# membuat variable hasil pengurangan x, y, dan z
hasil = x - y - z
# menampilkan output
print("\n\t{}[{}√{}] Hasil dari pengurangan {} - {} - {} =" .format(rt, gr, rt, x, y, z), hasil, rt)