Wednesday, May 15, 2024

Diploma Python Programming - Module 01 - Alison 03

KIta lanjutkan summary dari kursus Alison, dimana topik kali ini adalah programming dengan memakai bahasa Python. Kita juga memakai bahan kursus dari 



Image - Python Programming (credit to Google)

Se





JJJJJJJJJJJJJ



JJJJJJJJJJJJJJJJ

Python Beginner - Module 5 - Dave & Alison 01

 Terus berlanjut, kita sampai ke Module 5 dari Alison Course dan pelajaran ke 7 (video ke 7/24) dari Dave Gray.


Image (credit from Google)

Module & Package


Which of these is used to call a module from another file into your program? Choose one.
- using the import function
------------------------------------------------

Guessing Game

JJJJJ



JJJJJJJ

Monday, May 13, 2024

Python Beginner - Module 4 - Dave & Alison 01

Sekarang kita akan membahas Module 4 dari Alison Course dan Video ke 6 (6/24) dari Dave Gray. 


Image of Python for Beginners (credit to Google)

Functions
def myFunction():
    print('This is our function')

myFunction()
Run Python File:
This is our function

def betterPrint(string):
    for char in string:
        print(char)

betterPrint('hello')
Run Python File:
h
e
l
l
o

Which of these are the types of functions available in Python? Choose two.
- pre- defined function
- user defined function
-------------------------------------------

Variable Scope

Two types of Scope:
1) Global
- variable declared outside function

2) Local
variable declared inside function

x = 10
def function():
    global x
    x = 20

function()
print(x)
Run Python File:
20

True or False: Pre-defined scopes and user-defined scopes are the types of scopes available in Python.
- False
-----------------------------------------

Returning Data

Reverse
def reverse(string):
    print(string[::-1])

reverse('hello')
Run Python File
olleh


def reverse(string):
    return(string[::-1])

reverseString = reverse('hello')
print('data', reverseString)
Run Python File:
data olleh


Which of these refers to the factorial of 5? Choose three.
= 5 * 4!
= 5(4*3!)
= 5!
---------------------------------------------

Recursion

print(iterativeFactorial(3))
def iterativeFactorial(n):
    result = 1
    for i in range(n, 0, -1):
        result = result * i
    return result

print(iterativeFactorial(3))
Run Python File:
6 ...> 3*2*1 = 6

print(iterativeFactorial(5))
def iterativeFactorial(n):
    result = 1
    for i in range(n, 0, -1):
        result = result * i
    return result

print(iterativeFactorial(5))
Run Python File:
120 ...> 5*4*3*2*1 = 120


What do you call it when a function recalls itself several times for a purpose in Python programming? Drag the correct answer into the space provided.
- Recursion
--------------------------------------------


Tuples:
- immutable data

tuple ....> use ( )
tuple1 = (12, 13, 14, 15)
print(tuple1)
Run Python File:
(12, 13, 14, 15)

we can't change tuple assignment ...> immutable
tuple1 = (12, 13, 14, 15)
tuple1[1] = 16
Run Python File:
TypeError: 'tuple' object does not support item assignment


we can change tuple by list
tuple1 = (12,13,14,16)
list1 = list(tuple1)
list1[3] = 15 # Corrected index to 3 (since Python uses 0-based indexing)
tuple1 = tuple(list1)
print(tuple1)
Run Python File:
(12, 13, 14, 15)

Tuples in Python are denoted with what symbol? Choose one.
- answer: ( )
-------------------------------------

Dictionaries
We use "curl" bracket for dictionaries: { }
square backet for list: [ ]


employee = {
    'name' : 'John smith',
    'age' : 39,
    'salary' : '$10,000',
    'designation' : 'manager'
}

print(employee['name'], employee['salary'])
Run Python File:
John smith $10,000


for i in employee
employee = {
    'name' : 'John smith',
    'age' : 39,
    'salary' : '$10,000',
    'designation' : 'manager'
}

for i in employee:
    print(i)
Run Python File:
name
age
salary
designation


for key in employee
mployee = {
    'name' : 'John smith',
    'age' : 39,
    'salary' : '$10,000',
    'designation' : 'manager'
}

for key in employee:
    print(key + " : " + str(employee[key]))
Run Python File:
name : John smith
age : 39
salary : $10,000
designation : manager



The followings are the key points from this module:

The two types of Functions used in Python include: 
Predefined functions. 
User-defined functions. 

There are two types of scopes in Python and they are:
Global scope. 
Local scope. 

Recursion refers to when a function is called by itself over and over in order to achieve a result. 
Factorial, denoted by n!, is the product of all the numbers between 0 and that specific number. e.g. 4! = 4 * 3 * 2 * 1.
The factorial of 5, i.e 5!, can also be written as 5 * 4!.


Tuples are kind of lists that cannot be edited or amended but only read.
Tuples are denoted with ( ), instead of the [  ] as is the case in ordinary lists. 

Dictionaries are a list of key values which have specified value pair, where each key-value pairs are separated by a comma, and is denoted with the curly brackets ( {  } ).


=================================
===================================

Lesson from Dave Gray


Sekarang kita mempelajari lesson 6, yaitu List and Tuple.

users = ['Dave', 'John', 'Sara']

data = ['Dave', 42, True]

emptylist = []

print('Dave' in users)
print('Dave' in data)
print('Dave' in emptylist)
Run Python File:
True
True
False


users = ['Dave', 'John', 'Sara']

data = ['Dave', 42, True]

emptylist = []

print(users[0])
print(users[1])
print(users[-1])
print(users[-2])
Run Python File:
Dave
John...> 1
Sara
John...> -2


Users Index
users = ['Dave', 'John', 'Sara']

print(users.index('Dave'))
print(users.index('John'))
print(users.index('Sara'))
Run Python File:
0
1
2


Tambah (append) Elsa
users = ['Dave', 'John', 'Sara']

users.append('Elsa')
print(users)
Run Python File:
['Dave', 'John', 'Sara', 'Elsa']

Adding Jason, using +=
users = ['Dave', 'John', 'Sara']

users.append('Elsa')
print(users)

users += ['Jason']
print(users)
Run Python File:
['Dave', 'John', 'Sara', 'Elsa', 'Jason']

User extend
users = ['Dave', 'John', 'Sara']

users.append('Elsa')
print(users)

users += ['Jason']
print(users)

users.extend(['Robert', 'Jimmy'])
print(users)
Run Python File:
['Dave', 'John', 'Sara', 'Elsa', 'Jason']


Tuples ....> a kind of list that can't be changed or deleted

mytuple = tuple(('Dave', 42, True))

anothertuple = (1, 4, 2, 8)

print(mytuple)
print(type(mytuple))
print(anothertuple)
print(type(anothertuple))
Run Python File:
('Dave', 42, True)
<class 'tuple'>
(1, 4, 2, 8)
<class 'tuple'>




JJJJJJJJJJJJJJJJJJJJJJJ

JJJJJJJJJJJJJJJJJJJJJJJJJJJ

Sunday, May 12, 2024

Karier Sebagai Python Developer

 Ada sekitar 14 ribu lowongan kerja per hari untuk Python Developer di dunia, di Amerika Serikat sendiri ada 300 lowongan kerja per hari yang diiklankan di berbagai media.



Image Python Developer (Credit to Google).

Gajinya di kisaran US$107 ribu (Rp 1,6 milyar) per tahun. Angka yang cukup menggiurkan untuk pemula.

Untuk menjadi Python Developer, anda bisa ikut kursus gratis yang diselenggaran secara online oleh Alison.com (diakreditasi oleh UK). 

Badan akreditasinya adalah CPD UK (the continuing professional development institution in the United Kingdom).
 
Diantara kursus (sertifikat dan diploma) adalah sbb:
1) Sertifikat Python for Beginner
2) Diploma in Python for beginner
3) Diploma in Python programming

Kursus tambahan:
Diploma in Visual Basic Programming.








JJJJJJJ
JJJJJJ

Friday, May 10, 2024

Python Beginner - Module 3 - Dave & Alison 01

 Kita sudah membuat summary untuk Module 1 dan 2 dari Alison Course dan video 1, 2, 3 dan 4 dari Dave Gray.


Image of Python for Beginners (credit to Google)


Boolean
True: 1
False: 0

and
0   0 ...> 0
0   1 ...> 0
1   0 ...> 0
1   1 ...> 1

or
0   0 ...> 0
0   1 ...> 1
1   0 ...> 1
1   1 ...> 1

XOR ---> Exclusive OR
0   0 ...> 0
0   1 ...> 1
1   0 ...> 1
1   1 ...> 0

True or False: Boolean variable values can only be either true or false.
- True
----------------------------------------------

Module 3 - Chapter 2

Ini adalah chapter tentang "conditions" di Python.

== ...> equal to
!= ...> not equal to
>...> greater than
< .... less than
>= ... greater than equal to

minMarks = 30
studentMarks = float(input('enter your mark: '))
 
if studentMarks > minMarks:
    print("you are eligible")
else:
  print("you are not eligible")
Run Python File:
enter your mark: 40
you are eligible

enter your mark: 12
you are not eligible


elif studentMarks >= 25:
minMarks = 30
studentMarks = float(input('enter your mark: '))
 
if studentMarks > minMarks:
    print("you are eligible")
elif studentMarks >= 25:
   print("you have been put in waiting list")25
else:
  print("you are not eligible")
Run Python File:
enter your mark: 25
you have been put in waiting list

enter your mark: 31
you are eligible

urutan:
if
elif
else

Which of these are conditional operators in Python? Choose three.
- equal to
- greater than
- less or equal to
----------------------------------------------

Module 3, Chapter 3

Ada dua type Loops:
1) Iterative
- doing over and over or repetition.
- for

2) Conditional
- while

# Iteration / for loop
for i in 'string':
    print(i)

# conditional / while loop
i = 1
while i <= 50:
    print(i)
    i += 1 # i = i + 1
Run Python File:
s
t
r
i
n
g
1
2
3
.
.
.
49
50

Which of these is used to denote a list in Python? Choose one.
- [ ]
-------------------------------------------------------

Module 3, Chapter 4

List adalah connection of similar objects

print(fruits)
fruits = [
    'apple', # 0
    'banana', # 1
    'pear', # 2
    'strawberries', # 3
]
print(fruits)
Run Python File:
['apple', 'banana', 'pear', 'strawberries']

print(fruits[2])
fruits = [
    'apple', # 0
    'banana', # 1
    'pear', # 2
    'strawberries', # 3
]
print(fruits[2])
Run Python File:
pear

print(fruits[:2])
fruits = [
    'apple', # 0
    'banana', # 1
    'pear', # 2
    'strawberries', # 3
]
print(fruits[:2])
Run Python File:
['apple', 'banana']
-----------------------------------------

Module 3, Chapter 5

Mari kita mempelajari List operation

We can change value from 'd' to 'c'
characters = ['a', 'b', 'd', 'd']
print(characters)
characters [2] = 'c'
print(characters)
Run Python File:
['a', 'b', 'd', 'd']...> there are two 'd'

['a', 'b', 'c', 'd']...> 'd' is replaced by 'c'

>>> characters = ['a', 'b', 'd', 'd']
>>> len(characters)
4

>>> characters.append('f')
>>> characters
['a', 'b', 'd', 'd', 'f']
>>> characters.remove('f')       
>>> characters
['a', 'b', 'd', 'd']

['a', 'b', 'd', 'd']
>>> characters.pop(3)
'd'

>>> 'b' in characters
True
>>> 'z' in characters
False

Which of these is not one of the list operations in Python? Drag the correct answer into the space provided.
- characters.insert()
-----------------------------------------------------------------------

Module 3, Chapter 6
Bubble Sort:

Bubble sort adalah simple sorting algorithm

list = [8, 3, 1, 4]
print("Original list:", list)

length = len(list)
for i in range(length):
    for j in range(0, length - i - 1):
        if list[j] > list[j + 1]:
            list[j], list[j + 1] = list[j + 1], list[j]

print("Sorted list (ascending order):", list)
Run Python File:
Original list: [8, 3, 1, 4]
Sorted list (ascending order): [1, 3, 4, 8]
-----------------------------------------------

Module 3, chapter 7

Beberapa operators akan kita pelajari
>>> a = 12
>>> if (a > 6) and (a < 20):
...     print(a)
... 
12

Q1: cari binary angka 13
- bagi angka 13 dengan 2: 13/2= 6 ...> reminder 1....> first binary.
- then, 6/2 = 3 ...> reminder 0 ...> second binary
- then, 3/2 = 1 ...> reminder 1 ...> third binary
- kemudian, 1/2 = 0 ...> `reminder 1 ...> fourth binary
Untuk mengetahui binary angka 13, dilihat dari bawah (belakang) atau dari langkah ke 4 (fourth binary): 1101

>>> bin(13)
'0b1101' ...> 1101


Q2: cari angka berapa dari binary 0b1100 atau 1100?
- mulai dari sebelah kanan, yaitu 0
- decimal equivalent 0 = 0 x 2^0 = 0
-  decimal equivalent 0 = 0 x 2^1 = 0
decimal equivalent 1 = 1 x 2^2 = 4
decimal equivalent 1 = 1 x 2^3 = 8
Then, 0 + 0 + 4 + 8 = 12

Q3: 12|13 ...> 12 or 13
binary 12 = 1100
binary 13 = 1101
-------------------------------
                = 1101
Convert to value from right: 1(2*0) + 0(2*1) + 1(2*2) + 1(2*3) = 1+0+4+8 = 13
proved by VSC: 
>>> 12|13
13

Q4, Now find 12&13
binary 12 = 1100
binary 13 = 1101
--------------------------
                = 1100
convert to value from right: 0(2*0) + 0(2*1) + 1(2*2) + 1(2*3) = 0 + 0 + 4 + 8 =12
proved by VSC:
>>> 12 & 13
12

Q5, find 12 xor 13
>>> 12 ^ 13
1

True or False: A bubble sort consists of three types of loop.
- False
- True: one type of loop.
 
The followings are the key points from this module:
Boolean logic refers to the idea that all values are either true or false. 

Some boolean operations that were examined include:
and
or
Xor

Some conditional operators that were mentioned include:
Equals to which is written as ==. 
Not equals to which is written as !=. 
Greater than and Less than which are written as > and < respectively. 
Greater than or equals to which is written as >=. 
Less than or equals to which is written as <=. 

The following are the two types of Loops examined in this module: 
Iterative loop (For loop). 
Conditional loop (While loop). 

Lists are collections of similar objects and are denoted with "[  ]". 

The different operations that can be run on lists include: 
Changing character(s) of a list. 
Len (characters) -- To check the length of a list. 
character.append ('e') -- To add the character "e" to the end of a list.
character.reverse -- To reverse the order of characters in a list.

Bubble Sort refers to a simple algorithm that goes over an array and sorts it into the correct order. 



==============================================
==============================================

Dave Gray

Lesson 5/24


Kita akan mempelajari user input dan control flow

import random

print("Rock, Paper, Scissors Game")
print("1 for Rock, 2 for Paper, or 3 for Scissors")

playerchoice = input("Enter your choice (1/2/3): ")
player = int(playerchoice)

if player < 1 or player > 3:
    sys.exit("You must enter 1, 2, or 3.")

computerchoice = random.choice(["1", "2", "3"])
computer = int(computerchoice)

print("\nYou chose:", playerchoice)
print("Python chose:", computerchoice)
Run Start Debugging:

Rock, Paper, Scissors Game
1 for Rock, 2 for Paper, or 3 for Scissors
Enter your choice (1/2/3): 1

You chose: 1
Python chose: 3







JJJJJJJJJJJJJJJJJJ


JJJJJJJJJJJJJJJJJJ