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

TA MODUL 4 (VERSI 3)

Quiz
•
Computers
•
University
•
Medium
Ibes Ibes
Used 4+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
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.
Create a free account and access millions of resources
Similar Resources on Quizizz
15 questions
Python

Quiz
•
University
12 questions
Python Quiz

Quiz
•
University
10 questions
PRETEST 1 SCRATCH

Quiz
•
1st Grade - University
8 questions
File Processing

Quiz
•
University
10 questions
KUIS PRAK. 9: MANAGEMENT FILE 😼

Quiz
•
University
15 questions
Install Debian 10

Quiz
•
University
10 questions
Visual Programming

Quiz
•
University
10 questions
TA MODUL 4 (VERSI 2)

Quiz
•
University
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade