wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Kuis Algoritma dan Pemrograman

Total questions: 27

Worksheet time: 50mins

Name
Class
Date
1.

What is the purpose of algorithms in programming?

a)

To store data

b)

To perform calculations

c)

To define a sequence of steps

d)

To create user interfaces

2.

Which of the following is a valid variable name in Python?

a)

1variable

b)

variable_1

c)

variable-name

d)

variable name

3.

What will be the output of the following code: print(2 + 3 * 4)?

a)

14

b)

20

c)

20.0

d)

14.0

4.

What is the result of the expression True and False?

a)

True

b)

False

c)

None

d)

Error

5.

Fill in the blank: The _______ statement is used to create a loop in Python.

a)

for

b)

while

c)

loop

d)

repeat

6.

What is the output of the following code: for i in range(3): print(i)?

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

Error

7.

Is the following statement True or False: Python is a compiled language.

a)

True

b)

False

8.

What will be the output of the following code: print('Hello' + ' World')?

a)

Hello World

b)

HelloWorld

c)

Error

d)

Hello + World

9.

In Python, which of the following is used to handle exceptions?

a)

try

b)

catch

c)

finally

d)

except

10.

What is the output of the following code: print(10 // 3)?

a)

3

b)

3.33

c)

4

d)

Error

11.

What will be the output of the following code: print(type([]))?

a)

b)

c)

d)

12.

Fill in the blank: The _______ function is used to get the length of a list.

a)

len

b)

length

c)

size

d)

count

13.

What will be the output of the following code: print(5 == 5)?

a)

True

b)

False

c)

None

d)

Error

14.

What is the output of the following code: print(3 != 2)?

a)

True

b)

False

c)

None

d)

Error

15.

Fill in the blank: The _______ statement is used to exit a loop.

a)

break

b)

continue

c)

exit

d)

stop

16.

What is the output of the following code: print(2 ** 3)?

a)

6

b)

8

c)

9

d)

Error

17.

What is the output of the following code: print(10 % 3)?

a)

1

b)

3

c)

0

d)

Error

18.

Fill in the blank: The _______ function is used to convert a string to an integer.

a)

int

b)

str

c)

float

d)

convert

19.

What is the output of the following code: print('1' + '1')?

a)

2

b)

11

c)

Error

d)

None

20.

What will be the output of the following code: print(1 == 1 and 2 == 2)?

a)

True

b)

False

c)

None

d)

Error

21.

What is the output of the following code: print(1 < 2 < 3)?

a)

True

b)

False

c)

None

d)

Error

22.

Fill in the blank: The _______ function is used to read input from the user.

a)

input

b)

read

c)

scan

d)

get

23.

What is the output of the following code: print(3 > 2)?

a)

True

b)

False

c)

None

d)

Error

24.

What will be the output of the following code: print(2 + 2 == 4)?

a)

True

b)

False

c)

None

d)

Error

25.

What is the output of the following code: print(4 // 2)?

a)

2

b)

2.0

c)

Error

d)

None

26-30.

Understanding Python Control Structures

Python is a versatile programming language that is widely used in various fields, including data science, web development, and automation. One of the fundamental concepts in Python is control structures, which allow programmers to dictate the flow of a program. Control structures include loops and conditional statements, which are essential for executing code repeatedly or making decisions based on certain conditions. In Python, the 'for' loop is commonly used to iterate over a sequence, such as a list or a string, while the 'while' loop continues to execute as long as a specified condition is true.

Variables in Python are used to store data, and they can hold different data types such as integers, floats, strings, and booleans. Understanding data types is crucial because it affects how data is manipulated and stored in memory. For instance, arithmetic operations can be performed on integers and floats, but not directly on strings. Python also supports complex data structures like lists, tuples, and dictionaries, which can store multiple values in an organized manner. These structures are particularly useful when dealing with large datasets or when the relationship between data points needs to be maintained.

Functions in Python are blocks of reusable code that perform a specific task. They help in organizing code, making it more readable and maintainable. A function is defined using the 'def' keyword, followed by the function name and parentheses. Functions can accept parameters, which are variables passed into the function, and they can return values using the 'return' statement. Python also allows the use of modules, which are files containing Python code that can be imported into other programs. This modular approach encourages code reuse and simplifies complex programming tasks.

Error handling is an important aspect of programming, as it helps in managing and responding to errors that occur during program execution. Python provides a robust error handling mechanism using try-except blocks, which allows programmers to catch and handle exceptions gracefully. File handling is another critical feature, enabling programs to read from and write to files. This is particularly useful for data processing tasks, where data needs to be stored or retrieved from external files. By mastering these concepts, students can develop efficient and effective Python programs that solve real-world problems.

26.

What is a fundamental concept in Python that allows programmers to dictate the flow of a program?

a)

Control structures

b)

Data types

c)

Functions

d)

Error handling

27.

Which loop in Python is used to iterate over a sequence like a list or a string?

a)

for loop

b)

while loop

c)

do-while loop

d)

repeat loop

28.

What keyword is used to define a function in Python?

a)

def

b)

function

c)

define

d)

lambda

29.

Which of the following data types can arithmetic operations be performed on in Python?

a)

Integers and floats

b)

Strings and booleans

c)

Lists and tuples

d)

Dictionaries and sets

30.

What mechanism does Python provide for error handling?

a)

try-except blocks

b)

if-else statements

c)

switch-case statements

d)

for-else loops

31-35.

In the bustling campus of a renowned university, a group of first-year Information Systems students gathered in the lecture hall for their 'Algorithm and Programming' class. The professor, known for his engaging teaching style, introduced a real-world problem to illustrate the concept of loops. He described a scenario where the university's library needed to track the number of visitors each day over a month. The task was to calculate the total number of visitors and identify the day with the highest footfall using Python loops.

The students were intrigued as the professor explained how a 'for' loop could iterate over the days of the month, accumulating the daily visitor count. He emphasized the importance of initializing variables correctly and using conditional statements to update the maximum visitor count. The professor also highlighted the role of a 'while' loop in scenarios where the number of iterations isn't predetermined, such as when tracking visitors until a certain threshold is reached.

As the lecture progressed, the professor posed a question to the class: 'If the library wants to offer a special discount on the day with the highest visitors, how would you determine that day using a loop?' The students were encouraged to think critically about the logic required to solve this problem. They discussed the need for nested loops and conditionals to compare daily counts and update the maximum value accordingly.

To reinforce the concept, the professor presented a multiple-choice question: 'Which loop structure is more efficient for iterating over a fixed number of days, and why?' The students debated the merits of 'for' versus 'while' loops, considering factors like readability and performance. This exercise helped them understand the practical applications of control structures in programming.

Next, the professor challenged the students with a true/false question: 'A 'while' loop is always more efficient than a 'for' loop for counting visitors over a fixed period.' This prompted a discussion on the nuances of loop selection based on the problem context. The students learned that while 'for' loops are generally preferred for fixed iterations, 'while' loops offer flexibility in dynamic scenarios.

Finally, the professor asked the students to write a short explanation of how they would implement a loop to solve the library visitor problem. This task required them to articulate their understanding of loop logic and control structures. By the end of the class, the students had a deeper appreciation for the power of loops in algorithmic problem-solving, ready to apply these concepts in their future programming endeavors.

31.

What was the real-world problem introduced by the professor to illustrate the concept of loops?

a)

Tracking the number of visitors to the library each day over a month

b)

Calculating the total number of books in the library

c)

Determining the busiest time of day in the cafeteria

d)

Organizing a university event schedule

32.

Which loop structure did the professor suggest is more efficient for iterating over a fixed number of days?

a)

For loop

b)

While loop

c)

Do-while loop

d)

Recursive loop

33.

What was the purpose of the 'while' loop as explained by the professor?

a)

To track visitors until a certain threshold is reached

b)

To iterate over a fixed number of days

c)

To calculate the total number of visitors

d)

To offer a special discount on the day with the highest visitors

34.

What question did the professor pose to the class regarding offering a special discount?

a)

How would you determine the day with the highest visitors using a loop?

b)

What is the best way to calculate the total number of visitors?

c)

How can you track visitors until a certain threshold is reached?

d)

What is the role of a 'while' loop in programming?

35.

What did the professor ask the students to write at the end of the class?

a)

A short explanation of how they would implement a loop to solve the library visitor problem

b)

A summary of the lecture

c)

An essay on the importance of loops in programming

d)

A report on the university's library system