Youngliving
Jetorbit Web Hosting

Belajar python untuk Pemula

Belajar Phyton untuk Pemula dengan mengenal berbagai jenis dan bentuk, fungsi yang kami rangkum dibawah ini supaya memang tidak lupa untuk belajar. Jika anda ingin belajar yuk, kita belajar bersama-sama agar lebih mengetahui beberapa program yang dapat anda langsung praktekkan di Visual Code anda.
==============================================================================================================================

name = input("Siapa nama kamu?")
hobby = input ("Apa hobimu?")
print (name + " hobimu adalah " + hobby)
tahun = input (" Tahun lahir :")
tahun = int(tahun)
umur = 2023 - tahun
print ("umur kamu adalah " + str(umur))
age = 31
massage = f" umur kami {age}"
print(massage)
len() fungsinya untuk menghitung angka (fungsi)
course = "Belajar Bareng Topik"
print ( course.upper()) / Metode untuk huruf besar semua
#metode huruf kecil semua
course = "Belajar Bareng Topik"
print ( course.lower())
#metode depan huruf kapital
course = "Belajar Bareng Topik"
print ( course.title())
metode mengubah/mengganti dengan replace
course = "Belajar Bareng Topik"
print ( course.replace("Bareng","bersama" ))
melakukan cek apakah dalam kalimat ada sebuah kata yang dicari (bareng)
course = "Belajar python bareng topik"
language = "python"
print (language in course)

================== Operator Matematika==================

** = Pangkat
/ = pembagian (float)
// = pembagian bulat
% = Modulo ()
tandakurung
perpangkatan
perkalian atau pembagian
penjumlahan atau pengurangan

================== Math Modul==================

fungsi round digunakan untuk membulatkan
number = 5.8
number = number(round)
print (number)
import math
number = 5.4
number = math.sqrt (number)
print (number)
'python 3 math module'

==================Kondisi if atau percabangan menggunakan if==================

is_day = True
is_night=True
if is_day:
print ("Selamat Siang")
elif is_night:
print ("Selamat Malam")
else:
print ("selamat pagi)

==================operator perbandingan==================

!= tidak sama dengan
== sama dengan
>= lebih dari sama dengan
|| di python pakai or

nilai = 9
if nilai >= 8:
print ("nilai kamu A")
elif nilai >= 7:
print ("nilai kamu B")
elif nilai >= 6:
print ("nilai kamu C")
else:
print ("Silahkan belajar lagi dengan tekun")

==================operator logika==================

nama = "Topik Nugroho"
by_pass_validation = False
if len(nama) > 3 or by_pass_validation:
print("Welcome")
else:
print("Nama terlalu pendek")

================== Perulangan menggunakan While==================

index = 1
while kondisi:
print ("jalan")
print ("finish)
index = 1
while kondisi: / harus bernilai true baru dijalankan
print ("jalan")
print ("finish)
index = 1
while index <= 5: #apakah indek kurang dari 5 (true)
print ("*"* index)
index += 1
print("finish")

==================Buat Game.py==================

trying = 0
secret_number = 7
limit = 3
while trying < limit:
guess_number=input("Masukkan angka (1-9): ")
guess_number=int(guess_number)
if guess_number == secret_number:
print("Selamat, anda menang")
break

trying += 1

==================Aplikasi kalkulator==================

( + - * / exit)
command = ""
while command != "exit":
command=input( "Perintah : ")
if command =="exit":
break
if command !="+"and command !="-"and command !="*"and command !="/":
print ("perintah tidak dapat dikenali")
continue
a=int(input("Angka Pertama:"))
b=int(input("Angka Pertama:"))
if command =="+":
result= a + b
elif command =="-":
result= a - b
elif command =="*":
result= a * b
elif command =="/":
result= a / b
print (f"Hasil : {result}")
print ( "Terima Kasih Sudah Menggunakan Aplikasi Kami")

================== Perulangan For==================

numbers =[ 1,2,3,4,5]
for item in range (1,11,2) #mulai awal range dari angka 1, batas atas 11, dan kemudian, tambahnya dua
print(item)

==================list di python==================

kalau di program lain pakai Array bisa menampun banyak tipe data dari string, boolean dan angka dan biasanya isinya lebih sama bukan ketiganya
name =["Topik", "zelda", "nawa"]
print(name [1:3])
names =["Topik", "zelda", "nawa"]
for name in names:
print(f"Nama: {name}")

==================list Metode==================

numbers = [5,6,7,8,1]
numbers.append(99) #menambahkan angka baru dibelakang
numbers.insert(2, 100) # memasukkan di indek ke dua
numbers.pop (5) #menghilangkan indek ke lima
numbers.remove (8) #MENGHILANGKAN YANG ADA DI LIST
numbers.sort ()
print (numbers)

==================menjumlahkan list==================

numbers = [5,6,7,8,1]
init_number = 0
for number in numbers:
init_number= init_number + number
print(init_number)
#bisa cara pakai fungsi
numbers =[ 5,6,7,8,1]
total = sum(numbers)
print(total)
#mencari angka max
#carapertamamendapatkanangkapalingbesar
numbers = [ 5,6,7,8,1]
max_number = max(numbers)
print (max_number)
#carakeduamendapatkanangkapalingbesar
numbers = [ 5,6,7,8,1]
numbers.sort()
max_number = numbers[-1]
print (max_number)
#caraketigamendapatkanangkapalingbesar
numbers = [5, 6, 7, 8, 1]
max_number = numbers[0]
for number in numbers:
if number > max_number:
max_number= number
print(max_number)

================== tuple==================

numbers = ( 5,3,1,2,4,) #immutabel nilai nggak bisa diubah
numbers = numbers.index(3)
print(numbers)

==================unpack ==================

numbers = (1,2,3)
x = numbers [0]
y = numbers [1]
z = numbers [2]
print (x)
cara termudah menggunakan unpack
numbers = (1,2,3)
x,y,z = numbers
print (z)

==================Dictionary / Kamus Rubby Hash menggunakan kurung kurawal==================

user = {
"name": "Agung Setiawan",
"age" : 30,
"is_admin": True
}
name = user ["name"]
print ("")
print (name)
temp =user.get ("username","agungsetiawan")
user["username"] = "agung_setiawan"
user ["name"] = "Agung S"
user["username"] = "agung_setiawan"
print ("")
print (name)

================== Aplikasi Terbilang==================

numbers = input ("Masukkan Angka : ")
numbers_mapping = {
"1" : "satu",
"2" : "dua",
"3" : "tiga",
"4" : "empat",
"5" : "lima",
"6" : "enam",
"7" : "tujuh",
"8" : "delapan",
"9" : "sembilan",
"10" : "sepuluh",
}
output =" "
for n in numbers:
terbilang= numbers_mapping.get(n,"invalid")
output= output + terbilang +" "
print (output)

==================Emoji Converter==================

message = input (">>>")
emoji_mapping = {
":)" : "😀",
":D" : "😀",
":|" : "😀"
}
words = message.split(" ")
output =" "
for w in words:
output= output + emoji_mapping.get(w,w) +" "
print(output)

==================fungsi==================

def halo_user():
print("Halo User")
print("Selamat Belajar Python")
print("Star")
halo_user()
print("finish")

==================Parameter Fungsi========

def halo_user(nama, level):
print(f"Halo {nama} - {level}")
print("Selamat Belajar Python")
print("Start")
halo_user("topik", 8 )
print ("===========")
halo_user ("zelda", 10)
print("finish")

=================== Keyword Argument========

def halo_user(nama, level):
print(f"Halo {nama} - {level}")
print("Selamat Belajar Python")
print("Start")
halo_user( level = 8 , nama = "Agung") Keyword argumen
print("finish")
def halo_user(nama, level):
print(f"Halo {nama} - {level}")
print("Selamat Belajar Python")
print("Start")
halo_user( "topik", 8)
calculate_total_cost ( total_price =1000000, shipping_cost=50000, discount =50000) #keyword argument
print("finish")

==============return Statment====================

def halo_user(nama, level):
print(f"Halo {nama} - {level}")
print("Selamat Belajar Python")
return
temp = halo_user("topik" , 100)
print(temp)
def multiply (a, b,c):
result= a * b + c
return result
result = multiply (3,20,40)
print (result)
===================
def multiply (a, b,c):
# result = proses yang panjang
return a * b + c
result = multiply (3,20,40)
print (result)

++++++++++++++++++++++++++
================Exception============

try:
level=input ("level kamu berapa?")
level=int(level)
level= level /0
print (level)
except ZeroDivisionError:
print("Eror tidak bisa dibagi dengan nol")
except ValueError:
print ("yang kamu masukkan bukan angka")

=================== general Exception ========

try:
level=input ("level kamu berapa?")
level=int(level)
level= level /0
print (level)
except:
print("terjadi kesalahan")

=================== Membaca File ========

print(user.read()) #membaca secara keseluruhan
print(user.readline()) #membaca baris
users = open("user.txt", "r")
aray = users.readlines()
index = 1
for user in aray:
print(f"{index} - {user}")
index += 1
users.close()

=================== Menulis File ========

users = open("user.txt", "r")
aray = users.readlines()
index = 1
for user in aray:
print(f"{index} - {user}")
index += 1
users.close()

=================== Menulis File ========

users = open("user.txt", "w")
print (users.readable())
print (users.writable())
users.close()
++++++++++++++++++++++++++++
users = open("user.txt", "w")
user.write ("\nlink-link") #menambah data baru di bagian belakang
users.close()

=================== Membaca file csv ========

import csv
users = open("file.csv", "r")
user_csv = csv.reader(users,delimiter=",")
for row in user_csv:
print (f"Name : {row[0]}. Username: {row[1]}. Role: {row[-1]}")
user.close()

=================== with block========

import csv
#users = open("file.csv", "r")
with open ("file.csv", "r") as users:
user_csv= csv.reader(users,delimiter=",")
for row in user_csv:
print (f"Name : {row[0]}. Username: {row[1]}. Role: {row[-1]}")

=================== Module Python========

import matematika
result = matematika.plus (10,9)
result2 = matematika.minus (10,9)
print (result)
print (result2)
juga bisa menggunakan
import matematika
from matematika import plus
result = plus (10,2)
print (result)

=================== Package========

from marketplace.matematika import plus, minus
result = plus (10,8)
print (result)
result = minus (10,8)
print (result)

=================== Random ========

import random
print (random.random())
import random
for index in range (5):
print (random.randint(10,30))
import random
users = [ "agung", "topik", "nisa", "faza", "kiya"]
batas_bawah = 0
batas_atas = len (users) -1
random_int = random.randint(batas_bawah, batas_atas)
# for i in range(5):
# random_int = random.randint(batas_bawah, batas_atas)
# print (random_int)
winner = users [random_int]
print(winner)

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

import random
users = [ "agung", "topik", "nisa", "faza", "kiya"]
winner = random.choice(users)
print(winner)

=================== PIP VIRTUALVIEW ========

menginstll paket yang sudah disediakan orang lain dan kita sering menggunakan pemrograman orang lain dengan cara
untuk menginstal silahkan ketik "pip install cowsay"
untuk mac os menginstall inveronment python3 -m pip install --user virtualenv
untuk mengaktifkan gunakan source venv/bin/activate
import cowsay
cowsay.cow ("saya sedang belajar python")
def f(x):
returnstr(x *3) +'!'
print(f('informatika'))

========= MENGENAL FUNGSI ================

perusahaan = 'microsoft'
list_pulau = ['jawa', 'sumatera', 'sulawesi']
mahasiswa = {
'nama' : 'lendis febri',
'asal' : 'jogja'
}
print( "apakah 'c'ada di perusahaan? " ,
'c'in perusahaan
)
print( "apakah 'z' tidak ada di variabel perusahaan? " ,
'c'not in perusahaan
)
print ( "Apakah 'Madura'ada di variabel list_pulau? " , 'madura' in perusahaan
)
print(
"Apakah 'Madura' tidak ada variabel di list_pulau? " , 'madura'notinperusahaan
)
print(
"apakah atribut 'nama' ada di variabel mahasiswa?", 'nama'inmahasiswa
)
list_a =[1,2,3]
list_b = [1,2,3]
print( list_a is list_b)
print (list_a is not list_b)
print (id (list_a))
print (id (list_b))
print (format(0, '08b'))
a = 64
b = 376
print ( 'a=', a , '=', (format (a , '08b')))
print ( 'b=', b , '=', (format (b , '08b')))
print ( 'jumlah a & b =', a & b)
print (format (a, '08b'), '&', format (b , '08b'), '=', format ( a & b, '08b'), '\n')
# Input jumlah triangular yang telah ditentukan
jumlah_triangular = 4
# Hitung jumlah bola karena belum diketahui ibaratkan nol
jumlah_bola = 0
#prosess dengan menggunakan perulangan
for i in range(1, jumlah_triangular + 1):
jumlah_bola+=i
#mencetak jumlah bola
print('Jumlah bola :', jumlah_bola)

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Situs ini menggunakan Akismet untuk mengurangi spam. Pelajari bagaimana data komentar Anda diproses.

DomaiNesia