NEW
Font size
WorksheetsPython Programming Quiz
Total questions: 30
Worksheet time: 10mins
Which of the following best describes Python as a programming language?
Low-level, domain-specific language
High-level, general-purpose programming language
Assembly language for hardware control
Markup language for web design
Why is Python considered a good choice for beginners?
It has complex syntax and limited libraries
It is only used for web development
It offers clean syntax, a large community, and rich libraries
It requires advanced programming knowledge to start
After installing Python, which application can you open to check the installed version?
IDLE
Notepad
Excel
Chrome
Which of the following is a strategic approach to confirm that Python is installed correctly and that you have the correct version for your operating system?
Open IDLE and run 'import sys' followed by 'print(sys.version)' to check the version output.
Restart your computer and assume Python is installed.
Search for Python in your file explorer and check for any folder named 'Python'.
Ask a friend if they think Python is installed.
You have written a Python script and saved it with a .py extension. What is the next step to execute your code according to best practices?
A) Double-click the file in the file explorer
B) Run the file from the terminal
C) Rename the file to .exe
D) Upload the file to a website
Which of the following steps is necessary to run your first Python program as described in the material?
Create a file named hello.py and run it using the command python hello.py
Create a file named hello.txt and run it using the command python hello.txt
Create a file named world.py and run it using the command python world.py
Create a file named hello.py and run it using the command python3 world.py
What output should you expect to see in the terminal after running the code print("Hello, world!") in hello.py?
Hello, world!
Hello world
"Hello, world!"
Hello, Python!
How would you write a multi-line docstring in a Python function or module?
Using single quotes '...'
Using double quotes '...'
Using triple quotes '...'
Using hash symbols #...#
Which operator in Python is used to calculate the remainder of a division?
//
%
**
/
What is the result of the following Python code? print("Hello" + " " + "Python")
A. Hello Python
B. HelloPython
C. Hello + Python
D. "Hello" "Python"
Given the code print("-" * 10), what will be the output?
A. ----------
B. -10
C. 10-
D. ---------
How would you print a tab character between two words in Python?
A. print("Word1\tWord2")
B. print("Word1\nWord2")
C. print("Word1\\Word2")
D. print("Word1\"Word2")
Consider the code: print("python".replace("py", "Py")). What is the output and why?
"Python", because "py" is replaced with "Py"
"pyPython", because "py" is added to "Python"
"Py", because only "py" is kept
"python", because nothing changes
How can you control how items are separated and what happens at the end of the line when using the print() function in Python?
By using the sep and end parameters
By using the input() function
By using the split() method
By using the join() method
Given the following code: name = input("Enter your name: ") print("Hello,", name) age = int(input("Enter age: ")) print("Next year:", age + 1) What will be printed if the user enters "Alice" for the name and "20" for the age?
Hello, Alice Next year: 21
Hello, 20 Next year: Alice
Hello, Alice Next year: 20
Hello, 21 Next year: Alice
How can you obtain a sublist from a Python list?
By using slices
By using the append method
By using the pop method
By using the reverse method
Which of the following is a correct way to create a tuple in Python?
t = [1, 2]
t = {1, 2}
t = (1, 2)
t = "1, 2"
Suppose you have a set s = {1, 2, 2, 3}. After creating the set, what will be the contents of s?
{1, 2, 3}
{1, 2, 2, 3}
{1, 3}
{2, 3}
How can sets be useful when working with data that may contain duplicate values?
Sets automatically remove duplicates, keeping only unique items
Sets sort the data in ascending order
Sets allow duplicate values to be stored
Sets convert all values to strings
Given the sets X = {1, 2} and Y = {2, 3}, what is the result of the difference operation X - Y?
{1}
{2}
{3}
{1, 3}
Which of the following is the correct way to create a dictionary in Python?
{key: value}
[key, value]
(key, value)
Which of the following statements about Python's if/elif/else blocks is correct?
A) Blocks are defined by using curly braces.
B) Blocks are defined by indentation, typically 4 spaces.
C) Blocks are defined by using semicolons.
D) Blocks are defined by using parentheses.
Given the following code, what will be printed? score = 78 if score >= 90: grade = "A" elif score >= 80: grade = "B" else: grade = "C" print(grade)
A) A
B) B
C) C
D) 78
If you use range(1,10,2) in a for loop, which sequence of numbers will be produced?
1 3 5 7 9
1 2 3 4 5
0 2 4 6 8
2 4 6 8 10
Why is it important to be careful to avoid infinite loops when using while loops?
Because the program may never stop running.
Because the loop will always print "Go!"
Because the loop will only run once.
Because the condition is always False.
In the step-by-step explanation, what happens when n becomes 0 in the while loop?
The loop stops and the next line after the loop is executed.
The loop continues to print 0.
The loop prints "Go!" inside the loop.
The loop restarts from n = 3.
If you want to exit a while loop early before the condition becomes False, which statement should you use?
break
continue
exit
stop
What happens if you set a default value for a function argument and do not provide a value when calling the function?
A) The function will raise an error.
B) The argument will be ignored.
C) The default value will be used.
D) The function will not execute.
If you want to override the default value of the 'greeting' argument in the greet function, which method should you use?
A) Use a positional argument for 'greeting'
B) Use a keyword argument for 'greeting'
C) Do not provide any argument
D) Change the function name
Why is it generally recommended to use return values instead of global variables in functions?
To avoid overusing globals and improve code maintainability.
To make variables accessible everywhere.
To increase the number of global variables.
To prevent functions from returning any value.
