-
Notifications
You must be signed in to change notification settings - Fork 11
add task-mini week 1 di md #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
defrianafandi
wants to merge
5
commits into
airlab-unsri:master
Choose a base branch
from
defrianafandi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # basic-python-course | ||
| # Basic-python-course | ||
|
|
||
| ## Week 1 | ||
|
|
||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: Hasilny bakal gini: headerheader jugaheader lagi |
||
|
|
||
| ```python | ||
| ''' | ||
|
|
@@ -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'] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.