Ukuran huruf
Lembar kerjaPython Basic Final
Total soal: 90
Worksheet time: 43hrs 4mins
What is programming, and why is it important for students to learn about it in today's world?
a) Programming is a type of video game.
b) Programming is the process of instructing a computer to perform tasks, and it's important for students to learn because it empowers them to solve problems and automate tasks.
c) Programming is a form of storytelling.
d) Programming is only relevant to professional software developers.
How would you explain the basic syntax of Python to a beginner, and why is Python often recommended as a first programming language for students?
a) Python is recommended for students because it has a complex syntax.
b) Python's syntax is difficult for beginners to grasp.
c) Python is recommended for its simple and readable syntax, making it accessible for beginners.
d) Python is recommended because it's the only language available for students.
What are some common use cases for input/output functions in Python, and how can students effectively use these functions to interact with their programs?
a) Input/output functions are only used by professional programmers.
b) Input/output functions in Python are used for making coffee.
c) Input/output functions are used to read and write data to/from files, and to interact with users through the command line or graphical user interfaces.
d) Input/output functions in Python are used for gaming purposes only.
=
+
*
%
What is a input?
A function that allows us to ask the user to enter some data.
To plug in something.
Data displayed on a screen.
A function
name = 'Dave'
print (name)
What is the proper syntax for Python comments?
<!-- Python comment -->
<comment> Python comment <comment>
# Python Comment
/* Python Comment */
What will be printed out?
x = 10
y = 10
print(x != y)
True
False
What will be printed out?
x = 5
y = 3
print(x == y)
True
False
The result of 10%2 will be :
1
5
2
0
Click all comparison operators
!=
*=
==
>=
=
Click all arithmetic operators
**
=
+=
-
%
Can you add 2.6 to "Cat"?
Yes! I'll demonstrate on the board!
No. You're probably nuts for thinking this.
Empty curly braces in an assignment statement will create which type of data structure?
(s = {})
List
Dictionary
Stack
Set
Which data structure stores key/value pairs?
Sets
Stacks
Lists
Dictionaries
Each key/value pair in a dictionary is separated by this symbol:
/
,
:
;
Choose all of the following which are built in data types in Python
dict
list
set
tuple
A dictionary is an example of a sequence ...
True
False
Which code will set the "Year" from 2006 to 2008?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
__________________________________
OUTPUT: 2008
birthday["Year"]=2008
birthday[Year]=2008
birthday [2008]
birthday[2006]=2008
What will this code do?
birthday = {
"Month": "January",
"Day": "01",
"Year":2006
}
for x in birthday:
print(x)
Prints all the key names in the dictionary
print all the key and value pairs is the dictionary
The dictionary dnry is initialized as follows:
dnry = {"L": 8, "W": 5, "H": 11}
Which statement will give you the value 5?
dnry[1]
dnry["W"]
dnry["5"]
dnry[2]
A collection of modules and packages that can be imported into a program is called a __________.
class
documentation
library
function
What is the extension of python library modules?
.mod
.lib
.code
.py
In python which is the correct method to load a module math?
include math
import math
#include<math.h>
using math
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
For tuples and list which is correct?
List and tuples both are mutable.
List is mutable whereas tuples are immutable.
List and tuples both are immutable.
List is immutable whereas tuples are mutable
Which is a correctly declared tuple?
a = ("orange", "yellow", "red")
a = "orange", "yellow", "red"
a = ["orange", "yellow", "red"]
a = "orangeyellowred"
Can you have an empty tuple z = () or an empty string w = []?
yes
no
If L1=[2,4,8,16], L2=[32,64] what is L1+L2
[2,4,8,16,32,64]
[2,4,8,16][32,64]
[2,4,8,16],[32,64]
None of the above
Suppose list1 is [1, 3, 2]
What is list1 * 2 ?
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
Unable to change.
Immutable
A particular way of organizing data in our programs.
Data Structure
A heterogenous, immutable data type that stores an ordered sequence of things.
Tuple
A heterogenous, mutable data type that stores an ordered sequence of things.
List
Add a particular item to the end of a list.
append()
Which of the following keywords marks the begining of the function block?
Func
define
def
function
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
Consider the line of code:
Label('Go Team', 200, 100)
What is the Label?
argument
parameter
function name
Rewrite this line of code correctly!
(a)
When defining a function, the definition must occur before it is called.
true
false
What does the following code output?
11, 9
16, 16
None, None
225, 117
Score = Score + 1
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
for i in 100 :
print ( i )
Syntax error
prints numbers 0 to 100
prints numbers 1 to 100
prints numbers 0 to 99
prints numbers 1 to 99
Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.
while loop
for loop
nested loop
infinite loop
Repeats instructions multiple times and automatically updates the counting number used in the loop.
while loop
for loop
nested loop
infinite loop
+ operator represents What data type uses quotation marks?
" "
String
Integer
Float
Number
Please select all floating point numbers:
1.444
34567
777.980
32.0
21
What data type would store the value: True
Boolean
String
Integer
Float
What is the data type of the following: "89 / 90"
String
Integer
Float
Number
A variable in Pyton is (a)
Which code will display the multiplication table of 3?
Which code will print only odd numbers ?
What is the data structure of days based on the following code:
days = ["Sunday","Monday","Tuesday"]
List
String
Numeric
Tuple
What is this symbol called? (*)
star
asterisk
apostrophe
multiplication
What is a comment in Python?
A note written in the program to help people understand the code. The computer ignores it.
Solving a math problem in the program to get one final answer.
A special word in Python that already has a job and cannot be used as a name.
A symbol like + or * that tells the computer to do math.
To add an item to the end of a list, what command can we use?
append()
insert()
split()
remove()
Comparing a dictionary to Python to a dictionary for words, ____________ is each word we look up_______ is definition of the word
value, key
key, attribute
method, value
key, value
thisList = ["square", "circle", "triangle", "octagon"]
print(thisList[3])
octagon
triangle
circle
square
Given the following dictionary, which code can add `Zip` as `10001`?
dictionary["Zip"] = "10001"
dictionary.update({"Zip": "10001"})
dictionary[0] = "Zip:10001"
dictionary[0] = ("Zip": "10001")
What will be printed to the screen when the following program is run?
my_list = [5, 10, 30, 40]
print(my_list[3])
5
10
30
40
Which data type is used to store whole numbers in Python?
float
str
bool
int
What is the syntax to check if two values are not equal in Python?
!==
!=
==
<>
What is the syntax to check if a value is greater than or equal to another value in Python?
>
>=
<
==
What is the syntax to check if a value is less than or equal to another value in Python?
<=
>=
==
>
What is the syntax to check if a value is greater than another value in Python?
a < b
a > b
a >= b
a == b
Which of the following correctly stores 'price' as a decimal number?
price = int ( input ("Price: ")
price = str( input ("Price: ")
price = float ( input ("Price: ")
price = input ("Price: ")
Which is the correct way to declare 3 variables, 'a' , 'b', 'c' to 1?
a = b = c = 1
a,b,c = 1
a == b
b == c
c == 1
abc = 1
Which of the following brackets are used for list?
{ }
[ ]
( )
| |
Which line has an error?
19
21
23
18
Which of the following will print 10?
print(7 + 3)
print("6 + 4")
print("5" + "5")
print("0" + 10)
_________________ is a decimal number.
Integer
Variable
String
Float
A special symbol that represents computations like addition, multiplication, or string concatenation.
A portion of the code that is able to perform a special action
A section of code that represents a command or action.
A basic units of data, like a number or string, that a program manipulates.
The following code is an example of which data type in Python:
x = [ 1, 2, 3]
Array
List
Tuple
Dictionary
Spaces are not important in Python.
True
False
Which of the following are valid Python arithmetic operators?
$
**
//
%
How do you declare and initialize a variable with the integer data type in Python?
(a)
What is the output?
My
Exam
Practice
Cloud
Tests
