Muat turun Python (ikut spesifikasi yang ditetapkan)
Muat turun editor - VisualStudio Code, Sublime Text atau notepad pun boleh.
KODING DAN MENGENALI PYTHON
Rujukan : Senarai kata kunci PYTHON
TUTORIAL CODING WITH PYTHON SAMPLE -01
# def multiply((a, b):
# return a*b
# multiply([2, 3, 4, 5])
# def multiply((a, b):
# return a*b
# multiply(2, 3, 4, 5)
def multiply(*list):
total = 1
for number in list:
total *= number
return total
print(multiply(2, 3, 4, 5))
---------------------------------------
OUTPUT
--------------------------------------
ctl+alt+N - Visual studio Python output
[Running] python -u "z:\hack\python\cobaan29.py"
120
[Done] exited with code=0 in 0.205 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -02
numbers = [1, 2, 3]
def increment(number: int, by: int = 1) -> tuple:
return (number, number + by)
print(increment(2, by=3)) # keyword argument
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan28.py"
(2, 5)
[Done] exited with code=0 in 0.203 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -03
numbers = [1, 2, 3]
def increment(number: int, by: int = 1) -> int:
return (number, number + by)
print(increment(2, by=3)) # keyword argument
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan27.py"
(2, 5)
[Done] exited with code=0 in 0.248 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -04
numbers = [1, 2, 3]
def increment(number, by):
return (number, number + by)
print(increment(2, by=3)) # keyword argument
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan26.py"
(2, 5)
[Done] exited with code=0 in 0.202 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -05
# def increment(number, by):
# pass #indentation
# print(increment(2,3))
#
def increment(number, by):
return (number, number + by)
print(increment(2, 3))
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan25.py"
(2, 5)
[Done] exited with code=0 in 0.259 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -06
# def increment(number, by):
# pass #indentation
# print(increment(2,3))
def increment(number, by):
return number + by
print(increment(2, 3))
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan24.py"
5
[Done] exited with code=0 in 0.262 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -07
# names = ["Ahmad", "Kabir"]
# for name in names:
# if name.startswith("A"):
# print("Found")
# break
# names = ["Ahmad", "Kabir"]
# found = False
# for name in names:
# if name.startswith("A"):
# print("Found")
# found = True
# break
# if not found:
# print("Not found")
# names = ["Ahmad", "Kabir"]
# found = False
# for name in names:
# if name.startswith("J"):
# print("Found")
# found = True
# break
# if not found:
# print("Not found")
#change statement with else
names = ["Ahmad", "Kabir"]
for name in names:
if name.startswith("J"):
break
else:
print("Not found")
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan23.py"
Not found
[Done] exited with code=0 in 0.233 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -08
# loops 2 types, for nad while
# for
# while
# for x in "Phyton":
# print(x)
# for y in "123456789":
# print(y)
# for j in ["a", "b", "c"]:
# print(j)
# for k in range(5):
# print(k)
# for l in range(2, 5):
# print(l)
# # skip by 2
# for m in range(0, 10, 2):
# print(m)
print(range(5))
# LIST
print(type(range(5)))
print([1, 2, 3, 4, 5])
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\tempCodeRunnerFile.py"
range(0, 5)
<class 'range'>
[1, 2, 3, 4, 5]
[Done] exited with code=0 in 0.237 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -10
umur = 22
if umur <= 18:
message = "Layak"
else:
message = "Tidak "
print(message)
# chaining operation operator = can be simplified
message = "Layak" if umur >= 18 else "Not eligible"
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\tempCodeRunnerFile.py"
Tidak layak
[Done] exited with code=0 in 0.276 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -11
umur = 22
if umur <= 18:
message = "Layak"
else:
message = "Tidak layak"
print(message)
# chaining operation operator
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan20.py"
Tidak layak
[Done] exited with code=0 in 0.231 seconds
**********************************************
Rujukan : Senarai kata kunci PYTHON
Muat turun editor - VisualStudio Code, Sublime Text atau notepad pun boleh.
KODING DAN MENGENALI PYTHON
Rujukan : Senarai kata kunci PYTHON
TUTORIAL CODING WITH PYTHON SAMPLE -01
# def multiply((a, b):
# return a*b
# multiply([2, 3, 4, 5])
# def multiply((a, b):
# return a*b
# multiply(2, 3, 4, 5)
def multiply(*list):
total = 1
for number in list:
total *= number
return total
print(multiply(2, 3, 4, 5))
---------------------------------------
OUTPUT
--------------------------------------
ctl+alt+N - Visual studio Python output
[Running] python -u "z:\hack\python\cobaan29.py"
120
[Done] exited with code=0 in 0.205 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -02
numbers = [1, 2, 3]
def increment(number: int, by: int = 1) -> tuple:
return (number, number + by)
print(increment(2, by=3)) # keyword argument
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan28.py"
(2, 5)
[Done] exited with code=0 in 0.203 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -03
numbers = [1, 2, 3]
def increment(number: int, by: int = 1) -> int:
return (number, number + by)
print(increment(2, by=3)) # keyword argument
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan27.py"
(2, 5)
[Done] exited with code=0 in 0.248 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -04
numbers = [1, 2, 3]
def increment(number, by):
return (number, number + by)
print(increment(2, by=3)) # keyword argument
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan26.py"
(2, 5)
[Done] exited with code=0 in 0.202 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -05
# def increment(number, by):
# pass #indentation
# print(increment(2,3))
#
def increment(number, by):
return (number, number + by)
print(increment(2, 3))
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan25.py"
(2, 5)
[Done] exited with code=0 in 0.259 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -06
# def increment(number, by):
# pass #indentation
# print(increment(2,3))
def increment(number, by):
return number + by
print(increment(2, 3))
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan24.py"
5
[Done] exited with code=0 in 0.262 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -07
# names = ["Ahmad", "Kabir"]
# for name in names:
# if name.startswith("A"):
# print("Found")
# break
# names = ["Ahmad", "Kabir"]
# found = False
# for name in names:
# if name.startswith("A"):
# print("Found")
# found = True
# break
# if not found:
# print("Not found")
# names = ["Ahmad", "Kabir"]
# found = False
# for name in names:
# if name.startswith("J"):
# print("Found")
# found = True
# break
# if not found:
# print("Not found")
#change statement with else
names = ["Ahmad", "Kabir"]
for name in names:
if name.startswith("J"):
break
else:
print("Not found")
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan23.py"
Not found
[Done] exited with code=0 in 0.233 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -08
# loops 2 types, for nad while
# for
# while
# for x in "Phyton":
# print(x)
# for y in "123456789":
# print(y)
# for j in ["a", "b", "c"]:
# print(j)
# for k in range(5):
# print(k)
# for l in range(2, 5):
# print(l)
# # skip by 2
# for m in range(0, 10, 2):
# print(m)
print(range(5))
# LIST
print(type(range(5)))
print([1, 2, 3, 4, 5])
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\tempCodeRunnerFile.py"
range(0, 5)
<class 'range'>
[1, 2, 3, 4, 5]
[Done] exited with code=0 in 0.237 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -10
umur = 22
if umur <= 18:
message = "Layak"
else:
message = "Tidak "
print(message)
# chaining operation operator = can be simplified
message = "Layak" if umur >= 18 else "Not eligible"
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\tempCodeRunnerFile.py"
Tidak layak
[Done] exited with code=0 in 0.276 seconds
TUTORIAL CODING WITH PYTHON SAMPLE -11
umur = 22
if umur <= 18:
message = "Layak"
else:
message = "Tidak layak"
print(message)
# chaining operation operator
---------------------------------------
OUTPUT
--------------------------------------
[Running] python -u "z:\hack\python\cobaan20.py"
Tidak layak
[Done] exited with code=0 in 0.231 seconds
**********************************************
Rujukan : Senarai kata kunci PYTHON
No comments:
Post a Comment