Search Header Logo

TA MODUL 4 (VERSI 3)

Authored by Ibes Ibes

Computers

University

Used 4+ times

TA MODUL 4 (VERSI 3)
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Apa yang terjadi jika kita membuka file yang tidak ada dengan mode "r"?

File akan dibuat otomatiS

FileNotFoundError

File akan dibuka kosong

Program akan berhenti

Answer explanation

Python akan raise FileNotFoundError jika mencoba membuka file yang tidak ada dalam mode read.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Perhatikan kode berikut:

   ```

   with open("file.txt", "r") as f:

       content = f.read()

       print(content.____)

   ```

   Method apa yang digunakan untuk menghitung jumlah baris?

count("\n")

linecount()

countlines()

getlines()

Answer explanation

Menghitung jumlah newline characters untuk mengetahui jumlah baris

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Bagaimana cara menambahkan satu baris teks di akhir file tanpa menghapus konten yang ada?

open(file, "w+")

open(file, "a")

   open(file, "r+")

open(file, "w")

Answer explanation

Mode "a" (append) menambahkan konten di akhir file tanpa menghapus konten yang ada.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Apa yang terjadi jika kita mencoba membuka file dalam mode "x" yang sudah ada?

File akan ditimpa

FileExistsError

File akan dibuka dalam mode read

Konten file akan dihapus

Answer explanation

Mode "x" raise FileExistsError jika file sudah ada.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Perhatikan kode berikut:

    ```

    with open("file.txt", "r") as f:

        print(f.____())

    ```

    Method apa yang membaca seluruh file sebagai list of lines?

readlines

readall

readline

read

Answer explanation

readlines() membaca seluruh file dan mengembalikan list of lines.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Bagaimana cara mengecek apakah sebuah file ada?

    ```

    import os

    print(____("file.txt"))

    ```

os.exists

os.path.exists

os.isfile

os.file.exists

Answer explanation

os.path.exists() mengecek keberadaan file atau direktori.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Apa fungsi dari mode "w+"?

Hanya membaca

Membaca dan menulis, menghapus konten

Membaca dan menulis, tidak menghapus konten

Hanya menulis

Answer explanation

 Mode "w+" menghapus konten lama dan memungkinkan membaca dan menulis.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?