<repo_name>kelvin04/basic-phyton<file_sep>/Final-Project/final_project.py
import smtplib
import os
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

final_project_file = "final_project.py"
email_list_file = "receiver_list.txt"

smtp_server = "smtp.gmail.com"
port = 587
server = smtplib.SMTP(smtp_server,port)


def set_txt_data_to_list():
    receiver_list = []
    try:
        list_from_txt = open(email_list_file)
        if os.stat(email_list_file).st_size == 0:
            print(f"File {email_list_file} tidak memiliki data")
        else:
            for receiver in list_from_txt.read().split("\n"):
                receiver_list.append(receiver)
            return receiver_list
    except:
        print(f"File {email_list_file} tidak ditemukan")


def login_to_gmail_server():
    global sender_email
    sender_email = str(input("Email : "))
    global sender_password
    sender_password = str(input("Password: "))
    try:
        server.starttls()
        server.login(sender_email, sender_password)
        print("Sukses login")
        return True
    except Exception:
        print("Gagal login, harap periksa kembali email dan password anda")
        return False


def set_email_content(email_receiver, email_subject, email_message, with_attachment):
    message = MIMEMultipart()
    message['From'] = sender_email
    message['To'] = email_receiver
    message['Subject'] = email_subject
    message.attach(MIMEText(email_message, 'plain'))

    total_files = get_total_attachments()

    if with_attachment.upper() == "Y":
        if total_files > 0:
            for f in os.listdir():
                with open(f, "rb") as file_attachment:
                    if f != final_project_file and f != email_list_file:
                        part = MIMEApplication(
                            file_attachment.read(),
                            Name=basename(f)
                        )
                        part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
                        message.attach(part)
        else:
            print("Tidak ada file yang dilampirkan")

    return message.as_string()


def send_email(email_receiver, email_content):
    try:
        print(f"Sedang mengirim email kepada {email_receiver}, harap tunggu")
        server.sendmail(sender_email, email_receiver, email_content)
        print(f"Email berhasil dikirim kepada {email_receiver}")
    except Exception:
        print(f"Email kepada {email_receiver} gagal dikirim")
    finally:
        server.quit()


def get_total_attachments():
    total_files= 0
    files_list = []

    for file_name in os.listdir():
        with open(file_name, "rb"):
            if file_name != final_project_file and file_name != email_list_file:
                files_list.append(file_name)
                total_files = total_files + 1

    if total_files > 0:
        print("File yang akan dilampirkan :", ", ".join(files_list))

    return total_files


def final_project_function():
    # Menyimpan daftar email ke dalam list
    receiver_list = set_txt_data_to_list()

    # Mengubah list data type menjadi string dengan koma, untuk pengiriman email dengan banyak tujuan
    receiver_list_str_type = ", ".join(receiver_list)

    print("Selamat datang di program pengirim pesan!")
    print("Silahkan input email dan password gmail anda")

    # Login ke gmail server
    credential = login_to_gmail_server()
    if credential:
        # Input dan menyimpan data pesan email
        email_subject = str(input("Input subjek email : "))
        email_message = str(input("Input pesan email : "))
        with_attachment = input("Apakah akan melampirkan file di email? (Y/N) : ")
        email_content = set_email_content(receiver_list_str_type, email_subject, email_message, with_attachment)

        # Mengirimkan email
        send_email(receiver_list, email_content)


final_project_function()
<file_sep>/README.md
# basic-phyton
Basic Phyton Learning From Indonesia AI
<file_sep>/Tugas-1/Soal-1.py
name = str(input("Input nama anda : "))
age = input("Input umur anda : ")
height = float(input("Input tinggi anda :"))

print(f"Nama saya {name}, umur saya {age} tahun dan tinggi saya {height} cm")
<file_sep>/Tugas-1/Soal-2.py
radius = input("Input jari-jari lingkaran : ")
try:
    radius_int = int(radius)
    area = 22 / 7 * radius_int ** 2
    area_float = round(area, 2)
    print(f"Luas lingkaran dengan jari-jari {radius} cm adalah {area_float} cm\u00b2.")
except ValueError:
    print("Anda harus menginput tipe data integer!")
<file_sep>/Tugas-1/Soal-3.py
theory_scores = int(input("Input nilai ujian teori : "))
practice_scores = int(input("Input nilai ujian praktek : "))

if theory_scores >= 70 and practice_scores >= 70:
    print("Selamat, anda lulus!")
elif theory_scores >= 70 and practice_scores < 70:
    print("Anda harus mengulang ujian praktek.")
elif theory_scores < 70 and practice_scores >= 70:
    print("Anda harus mengulang ujian teori.")
else:
    print("Anda harus mengulang ujian teori dan praktek.")<file_sep>/main.py
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


test = "test"
empat = 4
lima = 5

a,b,c = "hi",1,2.5


valid = True


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('test')
    print(empat + lima)
    print(test + " " + "{}".format(empat))
    print(c)
    print(valid)
    print(type(c))
    print(0 % 7)
    print(4 ** 2)
    print(type(str(4.2)))
    print(float('12'))
    print("commit2")
    print("commit3")
    print("commit 4")
    print("commit 5")
    print("commit 6")
    print("commit 7 from development")

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
<file_sep>/Tugas-2/Soal-1.py
contact_dict = {"names": [], "telephones": []}

def show_contact():
    contact_size = len(contact_dict["names"])
    if contact_size > 0 :
        print("\nDaftar kontak:")
        for i in range(contact_size):
            print("Nama:", contact_dict["names"][i])
            print("No Telepon:", contact_dict["telephones"][i])
    else:
        print("Belum ada kontak yang didaftarkan")

def add_contact():
    name = str(input("Nama: "))
    while True:
        try:
            telephone = int(input("No Telepon: "))
            break
        except ValueError:
            print("Anda hanya bisa input angka untuk no telephone")

    contact_dict["names"].append(name)
    contact_dict["telephones"].append(telephone)

def func_contact_list_menu():
    print("Selamat datang!")

    while True:
        print("\n-- Menu --")
        print("1. Daftar Kontak")
        print("2. Tambah Kontak")
        print("3. Keluar")
        menu = int(input("Pilih menu: "))
        if menu == 1:
            show_contact()
        elif menu == 2:
            add_contact()
        elif menu == 3:
            break
        else:
            print("Menu tidak tersedia")

    print("Program selesai, sampai jumpa!")

func_contact_list_menu()
