Search Header Logo

Python Control Structures

Authored by Ryandika M.Eng.Sc

Computers

University

Python Control Structures
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

12 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Bagaimana syntax yang benar untuk penggunaan if statement pada bahasa pemrograman Python?

if (condition)

if {condition}

if condition:

if [condition]

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Bagaimana cara menulis pernyataan if dengan beberapa kondisi yang harus dipenuhi?

if (condition1 ||| condition2)

if (condition1 && condition2)

if (condition1 & condition2)

if (condition1 || condition2)

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Apa tujuan dari pernyataan else dalam pernyataan if-else?

Untuk menghentikan eksekusi program.

Untuk mengulangi set instruksi dalam pernyataan if.

Untuk memberikan set instruksi alternatif ketika kondisi dalam pernyataan if adalah salah.

Untuk memeriksa apakah kondisi dalam pernyataan if adalah benar.

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Apa sintaks untuk perulangan for dalam Python?

for item in iterable:

# code to be executed

for key, value in dictionary.items():

# code to be executed

for i in range(n):

# code to be executed

for item in iterable:

# code to be executed

Answer explanation

The for loop in Python is used to iterate over a sequence of elements. In this case, the correct syntax for a for loop is 'for item in iterable:'. This loop will execute the code block for each item in the iterable.

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Bagaimana cara Anda menerapkan for loop pada sebuah list untuk menampilkan nilai dari list tersebut?

my_list = [1,2,3]

for i in my_list:

print(my_list[1])

my_list = [1,2,3]

for i in range(my_list):

print(my_list[1])

my_list = [1,2,3]

for item in my_list:

print(my_list[item])

my_list = [1,2,3]

for i,v in enumerate(my_list):

{print(my_list[i])}

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Apa tujuan dari fungsi range() dalam perulangan for?

Untuk melewati beberapa angka dalam urutan

Untuk membalik urutan iterasi

Untuk menghasilkan urutan angka untuk iterasi

Untuk menghasilkan urutan angka acak

7.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Apa sintaks untuk perulangan while dalam Python?

for condition in range:

if condition:

while condition:

while (condition):

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?

Discover more resources for Computers