Perhatikan kode berikut:
```
with open("file.txt", "w") as f:
f.write("Hello\nWorld")
print(____)
```
Apa yang harus diisi untuk mengetahui posisi kursor dalam file?
TA MODUL 4 (VERSI 2)
Quiz
•
Computers
•
University
•
Medium
Ibes Ibes
Used 3+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Perhatikan kode berikut:
```
with open("file.txt", "w") as f:
f.write("Hello\nWorld")
print(____)
```
Apa yang harus diisi untuk mengetahui posisi kursor dalam file?
f.tell()
f.pos()
f.position()
f.cursor()
Answer explanation
Method tell() mengembalikan posisi kursor saat ini dalam file.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Perhatikan kode berikut:
```
f = open("data.txt", "r")
line = f.____()
```
Method apa yang digunakan untuk membaca satu baris?
readnext
readline
readone
getline
Answer explanation
readline() membaca satu baris dari file.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Lengkapi kode berikut untuk membaca file dalam mode binary:
```
with open("image.jpg", ____) as f:
data = f.read()
```
"rb"
"b"
"binary"
"bin"
Answer explanation
Mode "rb" digunakan untuk membaca file dalam format binary.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Perhatikan kode berikut:
```
f = open("data.txt", "r")
lines = f.____().____()
```
Lengkapi kode untuk membaca semua baris dan menghapus newline character:
readlines, strip
read, splitlines
readlines, splitlines
read, strip
Answer explanation
readlines() membaca semua baris, splitlines() menghapus newline characters.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Perhatikan kode berikut:
```
with open("file.txt", "r") as f:
for ____ in f:
print(line)
```
Apa yang harus diisi untuk iterasi per baris?
word
char
line
text
Answer explanation
Dalam iterasi file, setiap iterasi menghasilkan satu baris.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Perhatikan kode berikut:
```
import os
os.____("file.txt")
```
Fungsi apa yang digunakan untuk menghapus file?
delete
remove
unlink
Semua jawaban benar
Answer explanation
delete, remove, dan unlink adalah sinonim untuk menghapus file.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Apa yang terjadi ketika file ditutup?
File dihapus dari disk
File dikembalikan ke sistem operasi
File dienkripsi
File dikompres
Answer explanation
Menutup file membebaskan sumber daya sistem.
15 questions
Quiz_03
Quiz
•
University
9 questions
Повторення пайтон3 панда
Quiz
•
University
10 questions
File Type Extensions
Quiz
•
8th Grade - University
10 questions
TA MODUL 4 (VERSI 3)
Quiz
•
University
10 questions
ICT315- 20SSL6142
Quiz
•
University
10 questions
KUIS PRAK. 9: MANAGEMENT FILE 😼
Quiz
•
University
7 questions
ICS113_Unix Commands
Quiz
•
University
8 questions
CSE 15L Lab 9
Quiz
•
University
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