Master Python Exam Questions: 40+ Practice Problems with Answers and Code Solutions
This article compiles over forty Python multiple‑choice questions, code snippets, and programming exercises covering data structures, control flow, functions, file handling, and more, each accompanied by the correct answer and explanations to help learners solidify their programming fundamentals.
Below is a collection of Python exam questions and programming tasks designed to test and improve your understanding of core programming concepts.
Multiple‑Choice Questions
1. Which description of data storage structure is correct? Answer: C – The logical structure of data is represented in the computer.
2. Which statement about linear linked lists is correct? Answer: D – Storage space is not necessarily contiguous, and the order of elements is arbitrary.
3. In a full binary tree of depth 7, how many leaf nodes are there? Answer: B – 64.
4. Which description of structured programming basic structures is wrong? Answer: C – "goto" is not a basic structure.
5. Which statement about Python inheritance is correct? Answer: B – Inheritance is a mechanism for classes to share attributes and operations.
6. Which description of the software crisis is wrong? Answer: C – The statement about obtaining the real part of a complex number is incorrect.
7. Which statement about Python testing is correct? Answer: D – The main purpose of testing is to discover errors in the program.
... (questions 8‑40 follow the same pattern, each with four options and the correct answer indicated).
Code Snippets and Expected Outputs
x = 12.34
print(type(x))Correct answer: B –
<class 'float'> x = 0o1010
print(x)Correct answer: A – 520
x = 10
y = 3
print(divmod(x, y))Correct answer: D –
(3, 1) for s in "HelloWorld":
if s == "W":
continue
print(s, end="")Correct answer: D –
HelloorldProgramming Tasks
1. Write a Python program that computes round(pow((3**4 + 5*6**7)/8, 0.5), 3) without importing any modules.
2. Using jieba, count the number of Chinese characters and words in a given sentence.
3. Draw a square of side 200 using the turtle library:
import turtle
d = 0
for i in range(4):
turtle.fd(200)
d = d + 90
turtle.seth(d)4. Count the occurrences of each university type in a list of 39 "985" universities.
File Handling Example
txt = open("book.txt", "r")
print(txt)
txt.close()The output shows the file object representation, e.g.,
<_io.TextIOWrapper name='book.txt' mode='r' encoding='utf-8'>.
Promotional Note
Python full‑stack, automation, web‑scraping, data analysis, Go blockchain, and AI courses will start on May 8, 2019, promising a 120‑day intensive program to boost Linux operations salaries.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
