Logo


Dataset

Employee Data

This practicum uses a dummy employee dataset containing five records with attributes: ID, name, age, salary, position, and performance rating.

# Dummy dataset karyawan
employees = [
    {"id": 1, "name": "Bagas",  "age": 25, "salary": 5000,  "position": "Staff",      "performance": "Good"},
    {"id": 2, "name": "Joan",   "age": 30, "salary": 7000,  "position": "Supervisor", "performance": "Very Good"},
    {"id": 3, "name": "Alya",   "age": 27, "salary": 6500,  "position": "Staff",      "performance": "Average"},
    {"id": 4, "name": "Dwi",    "age": 35, "salary": 10000, "position": "Manager",    "performance": "Good"},
    {"id": 5, "name": "Nabil",  "age": 40, "salary": 12000, "position": "Director",   "performance": "Very Good"},
]

2.5.2 — Conditional Statements

Bonus Calculation

Bonus is calculated based on performance rating: Very Good → 20%, Good → 10%, Average → 5%.

print("=== Bonus Karyawan ===")
=== Bonus Karyawan ===
for emp in employees:
    if emp["performance"] == "Very Good":
        bonus = emp["salary"] * 0.20
    elif emp["performance"] == "Good":
        bonus = emp["salary"] * 0.10
    else:
        bonus = emp["salary"] * 0.05
    print(f"Name: {emp['name']}, Bonus: {bonus}")
Name: Bagas, Bonus: 500.0
Name: Joan, Bonus: 1400.0
Name: Alya, Bonus: 325.0
Name: Dwi, Bonus: 1000.0
Name: Nabil, Bonus: 2400.0

2.5.3 — Loop Exercises

Soal 1 — For Loop: Salary > 6,000

Iterating through all employees and printing those whose salary exceeds 6,000.

print("=== Karyawan dengan Gaji > 6000 ===")
=== Karyawan dengan Gaji > 6000 ===
for emp in employees:
    if emp["salary"] > 6000:
        print(f"Name: {emp['name']}, Salary: {emp['salary']}")
Name: Joan, Salary: 7000
Name: Alya, Salary: 6500
Name: Dwi, Salary: 10000
Name: Nabil, Salary: 12000

Soal 2 — While Loop: Stop at Manager

Loop continues displaying employees until a Manager position is found, then stops using break.

print("=== Tampilkan sampai Manager ditemukan ===")
=== Tampilkan sampai Manager ditemukan ===
i = 0
while i < len(employees):
    emp = employees[i]
    if emp["position"] == "Manager":
        print(f"Name: {emp['name']}, Position: {emp['position']} (Stop here)")
        break
    print(f"Name: {emp['name']}, Position: {emp['position']}")
    i += 1
Name: Bagas, Position: Staff
Name: Joan, Position: Supervisor
Name: Alya, Position: Staff
Name: Dwi, Position: Manager (Stop here)

Soal 3 — Break: Stop When Salary > 10,000

Using break to exit the loop the moment an employee’s salary exceeds 10,000.

print("=== Break saat gaji di atas 10.000 ===")
=== Break saat gaji di atas 10.000 ===
for emp in employees:
    if emp["salary"] > 10000:
        print(f"(Stopped because {emp['name']} has a salary above 10,000)")
        break
    print(f"Name: {emp['name']}, Salary: {emp['salary']}")
Name: Bagas, Salary: 5000
Name: Joan, Salary: 7000
Name: Alya, Salary: 6500
Name: Dwi, Salary: 10000
(Stopped because Nabil has a salary above 10,000)

Soal 4 — Continue: Skip Average Performers

Using continue to skip any employee with an “Average” performance rating.

print("=== Skip karyawan Average ===")
=== Skip karyawan Average ===
for emp in employees:
    if emp["performance"] == "Average":
        continue
    print(f"Name: {emp['name']}, Performance: {emp['performance']}")
Name: Bagas, Performance: Good
Name: Joan, Performance: Very Good
Name: Dwi, Performance: Good
Name: Nabil, Performance: Very Good
print('(Alya is skipped because the performance is "Average")')
(Alya is skipped because the performance is "Average")