WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 159 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# basic-python-course
# Basic-python-course

## Week 1

Expand All @@ -7,16 +7,18 @@
```python
print('what to print')
```
- output :<br>
what to print

### How to write comments

#### Single Line
### Single Line

```python
# this is a single line comment.
```

#### Multi Line
### Multi Line
Comment on lines 13 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secara hierarki harusny header "Single Line" dan "Multi Line" itu bagian dari "How to write comments", jadi ukuranny harusny lebih kecil. Dk perlu di ubah lg.

kalo kw nulis gini di markdown:

## header
#### header juga
###### header lagi

Hasilny bakal gini:

header

header juga

header lagi


```python
'''
Expand All @@ -28,7 +30,158 @@ comment.
### How to declare variables

```python
a = 'some text' # declare a string variable
b = 123 # an integer
c = True # a boolean
a = 'some text' # declare a string variable
b = 123 # an integer
c = True # a boolean
d = "hello world" # declare a string variable menggunakaan tanda ("") petik dua
e = false # a boolean
f = 3.5 # a float
g = 2+3j # a complex
h = [1,2,3,4] # a list
i = ("w","o","r","l","d") # a tuple

```
### Conditional

```python
def test_conditional():
nama = "wenty"

if(nama == "wenty"):
print ("this is if")
elif (nama == "tiara"):
print ("this is elif")
else:
print("else")

test_conditional()
```
- output :<br>
this is if

### How to Looping

```python
def test_looping():
for x in range (0,5):
print("nilai x:",x)

i = 0
while (i<5):
print ("nilai i:",i)
i += 1

test_looping()
```
- output : <br>
nilai x: 0<br>
nilai x: 1<br>
nilai x: 2<br>
nilai x: 3<br>
nilai x: 4<br>
nilai i: 0<br>
nilai i: 1<br>
nilai i: 2<br>
nilai i: 3<br>
nilai i: 4

### Function and Exception

```python
def test_function_return_value(input_value):
return input_value * 2

print(test_function_return_value(4))
print("-----------------")

def my_function(temp_string):
print(temp_string + "<---")
return temp_string + "done"

print(my_function("Test 1"))
print(my_function("Test 2"))
print(my_function("Test 3"))
print("-----------------")

def your_function(temp_string):
try:
result = temp_string + 5
except TypeError:
print(temp_string + "<---")
finally:
print("yeaaay")

your_function("test 1")
your_function("test 2")
```
- output :<br>
8<br>
-----------------<br>
Test 1<---<br>
Test 1done<br>
Test 2<---<br>
Test 2done<br>
Test 3<---<br>
Test 3done<br>
-----------------<br>
test 1<---<br>
yeaaay<br>
test 2<---<br>
yeaaay

### Namespace

```python
global_var = 10
def test_namespace():
private_var = 5
global_var = 6

print ("private_var :", private_var)
print ("global_var :", global_var)

print("global_var:",global_var)
test_namespace()
```
- output :<br>
global_var: 10<br>
private_var : 5<br>
global_var : 6

### String Operator

```python
def test_string_operator():
full_string = "this is full string"
temp_string = "temp string"
upper_string = "THIS IS UPPER"
lower_string = "this is lower"

# Concat :
print(full_string+temp_string)
# Slicing :
print(full_string[3:6])
# Lower :
print(upper_string.lower())
# Upper :
print(lower_string.upper())
# Len :
print(len(full_string))
# Strip :
print(full_string.strip("t"))
# Replace :
print(full_string.replace("full","name"))
# Split
print(full_string.split("is"))

test_string_operator()
```
- output :<br>
this is full stringtemp string<br>
s i<br>
this is upper<br>
THIS IS LOWER<br>
19<br>
his is full string<br>
this is name string<br>
['th', ' ', ' full string']
13 changes: 13 additions & 0 deletions defrianafandi/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
my_list = []

my_list.append(1)
my_list.append(3)
my_list.append(5)

my_list.append(("Defrian", "Afandi", "Hasan"))

colors = {}
colors["Biru"] = "Blue"
my_list.append(colors)

print(my_list)
31 changes: 31 additions & 0 deletions defrianafandi/list_2D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
list2d = []
list2d.append([])
list2d.append([])
list2d.append([])
list2d.append([])


list2d[0].append(1)
list2d[0].append(1)
list2d[0].append(1)
list2d[0].append(1)

list2d[1].append(1)
list2d[1].append("-")
list2d[1].append("-")
list2d[1].append(1)

list2d[2].append(1)
list2d[2].append("-")
list2d[2].append("-")
list2d[2].append(1)

list2d[3].append(1)
list2d[3].append(1)
list2d[3].append(1)
list2d[3].append(1)

for y in list2d:
for x in y:
print(x, end=" ")
print()
22 changes: 22 additions & 0 deletions defrianafandi/list_comprhension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
angka = [1, 2, 3]
print("isi List : ", angka)

multiply8 = [ m * 8 for m in angka]
print("Nilai 8 kali dari isi elemen List : ", multiply8)

a = [1, 2, 3, 4, 5]
x = a + a
y = a * 3

print("a : ", a)
print("x : ", x)
print("y : ", y)

jumlah = sum(a)
print("jumlah dari a : ", jumlah)

terbesar = max(a)
print("Nilai maksimum dari a : ", terbesar)

terkecil = min(a)
print("Nilai minimum dari a : ", terkecil)
20 changes: 20 additions & 0 deletions defrianafandi/list_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
friends = ["Fahmi", "Tomi", "Ahmad", "Abi", "Ardi"]
for teman in friends:
print(teman)

print()
print(friends[0])
print(friends[3])
print(friends[2])
print(friends[4])
print(friends[1])

print()
print("Asli : ", friends)
friends.reverse()
print("Reverse : ", friends)

friends.pop()
print("Pop : ", friends)
friends.append("Ama")
print("Append : ", friends)
23 changes: 23 additions & 0 deletions defrianafandi/list_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
friends = ["Faiz Alauddin"]
friends.append("Ma'ruf")
print("Isi List : ", friends)

friends.insert(1, "Darmawan")
print("List My friends : ", friends)

print()
women_friends = ["Tsniyah", "Rahmawati", "Tasya", "Rini"]
friends.extend(women_friends[0:4])
print("Gabungkan List : ", friends)

print()
friends.sort()
print("Urutkan Berdasakan abjad : ", friends)

print()
friends.reverse()
print("Reverse : ", friends)

print()
friends.remove("Alauddin")
print("Remove Mustofa : ", friends)
25 changes: 25 additions & 0 deletions defrianafandi/tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
my_tuple = tuple(["Hot", "Cold", "Windy"])

print("Suhu : ", my_tuple)
# list berisi angka
a = (1, 2, 3, 4, 5)

# Tuple berisi karakter dan string
b = ('a', 'b', 'c', 'd')
c = ('Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat')

# Tuple berisi list, tuple, dan dictionary
d = ([1, 2, 3], [1, 2, 3], [1, 2, 3])
e = ((1, 2, 3), (1, 2, 3), (1, 2, 3))
f = ({'a':1, 'b':2, 'c':3},{'a':2, 'b':3, 'c':4},{'a':3, 'b':4, 'c':5})

# Tuple campuran
g = (1, 'b', 2, 'Hot', [1, 2, 3], (1, 2, 3), {'Cold':1, 'Windy':2})

print ("Tuple Angka : ", a)
print ("Tuple Karakter : ", b)
print ("Tuple String : ", c)
print ("Tuple berisi List : ", d)
print ("Tuple berisi Tuple : ", e)
print ("Tuple berisi Dictionary : ", f)
print ("Tuple Campuran : ", g)
13 changes: 13 additions & 0 deletions defrianafandi/tuple_immutable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Animal = ('bird', 'snake', 'mouse')

# This causes an error.
# TypeError: 'tuple' object does not support item assignment
# tuple[0] = 'cat'

#mengubah isi tuple harus diubah ke list dulu
t = list(Animal)
t[0] = "burung"
t[1] = "ular"
Animal = tuple(t)

print("Mengubah Isi Tuple : ", Animal)
11 changes: 11 additions & 0 deletions defrianafandi/tuple_pack_unpack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Create packed tuple.
fruits = ("5 kg", "Anggur", "Ungu")

# Unpack tuple.
(berat, Nama_Buah, warna) = fruits

# Display unpacked variables.
print("Berat : ", berat)
print("Nama Buah : ", Nama_Buah)
print("Warna : ", warna)
print("Isi List : ", fruits)
Loading