diff --git a/sendyram/course1.py b/sendyram/course1.py new file mode 100644 index 0000000..be2d0f1 --- /dev/null +++ b/sendyram/course1.py @@ -0,0 +1,49 @@ +def test_conditional(): + name = "Sendy" + + if(name == "Sendy"): + print("this is if") + elif(name == "Domu"): + print("this is elif") + else: + print("this is else") + +def test_looping(): + for x in range(0,5): + print("nilai x",x) + + i = 0 + while(i<5): + print("nilai i", i) + +#print(test_looping()) + +global_var = 10 +def test_namespace(): + private_var = 15 + print("private var = ",private_var) + print("global var = ",global_var) + +print(test_namespace()) + +def test_string_operator(): + full_string = "this is full string" + temp_string = "temp string" + upper_string = "this is upper" + lower_string = "this is lower" + + print(full_string+temp_string) + print(full_string[3:6]) + print(upper_string.lower()) + print(lower_string.upper()) + print(len(full_string)) + print(full_string.strip('t')) + print(full_string.replace("full","some")) + print(full_string.split(" ")) + +test_string_operator() + +def test_function(value): + return value; + +print(test_function(4)) \ No newline at end of file diff --git a/sendyram/dictionary.py b/sendyram/dictionary.py new file mode 100644 index 0000000..24fdb72 --- /dev/null +++ b/sendyram/dictionary.py @@ -0,0 +1,14 @@ +class kucing: + def __init__(__args__): + pass + + +animal = {} +animal["lion"] = 10 +animal["whale"] = 30 +animal[1] = "whale" + +you = kucing() +animal[you] = 1 + +print(animal) \ No newline at end of file diff --git a/sendyram/list.py b/sendyram/list.py new file mode 100644 index 0000000..c443255 --- /dev/null +++ b/sendyram/list.py @@ -0,0 +1,13 @@ +list = [] + +list.append(1) +list.append(2) +list.append(3) + +list.append(("Sendy", "Gugu")) + +plants = {} +plants["durian"] = 23 +list.append(plants) + +print(list) \ No newline at end of file diff --git a/sendyram/list2d.py b/sendyram/list2d.py new file mode 100644 index 0000000..825ddd9 --- /dev/null +++ b/sendyram/list2d.py @@ -0,0 +1,14 @@ +list2d = [] +list2d.append([]) +list2d.append([]) + +list2d[0].append(1) +list2d[0].append(2) + +list2d[1].append("Simpang") +list2d[1].append("Dogan") + +for y in list2d: + for x in y: + print(x, end=" ") + print() \ No newline at end of file diff --git a/sendyram/list_comprehension.py b/sendyram/list_comprehension.py new file mode 100644 index 0000000..61ded31 --- /dev/null +++ b/sendyram/list_comprehension.py @@ -0,0 +1,7 @@ +numbers = [1, 2, 3] + +multiply100 = [number * 10 for number in numbers] +print(multiply100) + +result = [number * 100 for number in numbers] +print(result) \ No newline at end of file diff --git a/sendyram/list_loop.py b/sendyram/list_loop.py new file mode 100644 index 0000000..083a626 --- /dev/null +++ b/sendyram/list_loop.py @@ -0,0 +1,3 @@ +students = ["Sendy", "Rizky", "Farhan", "Aras"] +for student in students: + print(student) \ No newline at end of file diff --git a/sendyram/list_method.py b/sendyram/list_method.py new file mode 100644 index 0000000..7188a4d --- /dev/null +++ b/sendyram/list_method.py @@ -0,0 +1,19 @@ +students = ["Sendy"] +students.append("Ramadhan") +print(students) + +students.insert(1, "D") +print(students) + +woman_students = ["Runu", "Rana", "Rini", "Rono"] +students.extend(woman_students[0:4]) +print(students) + +students.sort() +print(students) + +students.reverse() +print(students) + +students.remove("Ramadhan") +print(students) \ No newline at end of file diff --git a/sendyram/tuple.py b/sendyram/tuple.py new file mode 100644 index 0000000..1271288 --- /dev/null +++ b/sendyram/tuple.py @@ -0,0 +1,2 @@ +my_tuple = tuple(["box", "blue"]) +print(my_tuple) \ No newline at end of file diff --git a/sendyram/tuple_immutable.py b/sendyram/tuple_immutable.py new file mode 100644 index 0000000..63579f9 --- /dev/null +++ b/sendyram/tuple_immutable.py @@ -0,0 +1,3 @@ +tuple = ('box', 'blue', 'green') + +tuple[0] = 'box' \ No newline at end of file diff --git a/sendyram/tuple_pack_unpack.py b/sendyram/tuple_pack_unpack.py new file mode 100644 index 0000000..902ee44 --- /dev/null +++ b/sendyram/tuple_pack_unpack.py @@ -0,0 +1,5 @@ +pair = ("lion", "whale") +(key, value) = pair + +print(key) +print(value) \ No newline at end of file