NEW
Font size
WorksheetsPython workshop day2
Total questions: 20
Worksheet time: 7mins
What operator checks if two values are equal?
==
!=
>
<
The if statement is used for:
Looping through a sequence
Defining functions
Checking conditions and executing code based on the result
Storing data
How can you write an if statement that checks if a number is greater than 10?
if num > 10:
num > 10
if(num > 10)
greaterThanTen(num)
Python is a case-sensitive programming language
True
False
What is the purpose of defining a function?
To create a reusable block of code
To store data permanently
To define data types
To control the flow of the program
When calling a function, how do you pass arguments (values) to it?
Place them within parentheses after the function name
Use keywords to identify them
Both a and b are correct
Arguments are automatically assigned
If a function expects two arguments, what happens if you only provide one when calling it?
The function will behave unexpectedly
The function will ignore the extra argument
An error will occur
None of the above
How can you represent the boolean value True in Python?
'True'
true
True
0
numbers = [1, 2, 3, 4]
print(numbers[2:4])
[1, 2]
[3, 4]
Error
None
How can you check the data type of a variable in Python?
checkType(var)
typeof var
type(var)
dataType var
How can you iterate through the characters of a string using a loop?
for char in string:
loopThroughString(string)
string.loop(print(char))
There is no built-in way to loop through characters in Python.
x = 3
y = 2
print(x // y)
1
1.5
Error
None
Which of the following CANNOT be directly stored in a variable in Python?
Integer
Float
List
Function
x = 5
y = x
x = 10
print(y)
5
10
Error
None
name = "Alice"
greeting = "Hello, " + name + "!"
print(greeting)
Hello, name!
Hello, Alice!
Error
None
What is the purpose of the range() function in loops?
To define a counter variable
To create a sequence of numbers for iteration
To modify existing lists
To break out of a loop
How can you return a value from a function?
Use the return keyword followed by the value.
Functions inherently return the last evaluated expression.
Store the value in a global variable within the function.
Printing the value inside the function automatically returns it
age = 20
is_adult = age >= 18
print(is_adult)
True
False
Error
None
my_tuple = (1, 2, 3)
my_tuple = my_tuple + (4,)
print(my_tuple)
(1, 2, 3)
(1, 2, 3, 4)
Error
None
fruits = ["apple", "banana", "orange"]
print(fruits[1])
"apple"
"banana"
Error
None
