Time: 30 minutes
Total Questions: 20
What is the output of the following code?
name = "Alice"
age = 25
print(f"Name: {name}, Age: {age}")A: Name: Alice, Age: 25 ✅ 正确 - f-string格式化输出正确
Which of the following is NOT a valid Python data type? A) int B) string C) float D) char
A: B ✅ 正确 - string在Python中是一个类,不是基本数据类型,str才是
What will be the result of this expression?
10 // 3A: False
❌ 错误
你的答案: False
正确答案: 3
解释: // 是整除运算符,10除以3等于3余1,所以结果是3。注意这不是布尔判断。
Write a conditional statement that checks if a number num is positive and prints "Positive" if it is.
A: if(num>=0):
print("Positive") ❌ 错误 你的答案:
if(num>=0):
print("Positive")正确答案:
if num > 0: # 正数应该是严格大于0
print("Positive")解释: 0不是正数,正数的定义是大于0的整数。另外Python中不需要括号包围条件表达式。
How do you create a list in Python? Provide an example with 3 numbers.
A: List = [1,2,3] ✅ 正确 - 列表创建正确。注意Python中变量命名建议使用小写(list而不是List)
What is the difference between == and != operators?
A: == return True when 2 variables are equal in the value,!= return True when 2 variables are not equal in the value ✅ 正确 - 解释准确。建议写成更完整的句子:== 返回True当两个变量的值相等时,!= 返回True当两个变量的值不相等时
Write a for loop that prints numbers from 1 to 5.
A: for i in range(1,5)
print(i) ❌ 错误 你的答案:
for i in range(1,5)
print(i)正确答案:
for i in range(1, 6): # range是左闭右开,上限需要+1
print(i)解释: range()函数的第二个参数是上限但不包含,要包含5需要写成6。另外缺少了冒号。
What method would you use to add an element to the end of a list?
A: push() ❌ 错误 你的答案: push() 正确答案: append() 解释: Python中的列表使用append()方法添加元素到末尾,push()是JavaScript数组的方法。
What is the output of this code?
fruits = ["apple", "banana", "cherry"]
print(fruits[1])A: Banana ✅ 正确 - Python列表索引从0开始,fruits[1]确实是"banana"
How do you define a function in Python? Write a simple function that returns the square of a number.
A: def cal_squa(number: int):
return number*number ✅ 正确 - 函数定义正确。更好的写法:
def square(number): # 函数名建议使用snake_case
return number ** 2 # 使用幂运算更清晰理由: Python推荐函数名使用snake_case,幂运算符(**)对于平方运算更直观易读
What does the len() function do?
A: return the length of an iterator ❌ 错误 你的答案: return the length of an iterator 正确答案: return the length of a sequence (string, list, tuple, dictionary, etc.) 解释: len()函数可以计算任何序列(字符串、列表、元组、字典等)的长度,不仅仅是迭代器。
Write a while loop that counts down from 5 to 1.
A: result = 5
while result > 0:
print(result)
result -= 1 ✅ 正确 - while循环实现正确。注意result -= 1等同于result = result - 1
How do you access a value from a dictionary using its key?
A: use the key word,like dict["key"] ❌ 错误 你的答案: use the key word,like dict["key"] 正确答案: 使用方括号语法:dict["key"] 或 dict.get("key") 解释: 语法正确,但表述不够准确。应该直接给出代码示例。dict["key"]会抛出KeyError如果key不存在,dict.get("key")则返回None而不是报错。
What is the purpose of the range() function in a for loop?
A: control the times of loop ✅ 正确 - 解释正确。range()用于指定循环的次数和范围
Write a conditional statement that checks if a string contains the letter "a".
A: if string.find("a"):
print("get") ❌ 错误 你的答案:
if string.find("a"):
print("get")正确答案:
if "a" in string:
print("contains 'a'")解释: string.find("a")当找到"a"时返回0,在if语句中0是False,会导致逻辑错误。应该使用in操作符。
How do you remove an element from a list by its value?
A: list.remove("value") ✅ 正确 - 使用list.remove()方法正确。注意这个方法会移除第一个匹配的值
What is the output of this code?
print(2 ** 3)A: 8 ✅ 正确 - **运算计算2的3次方,结果确实是8
Write a function that takes two parameters and returns their sum.
A: def function(a:int,b:int):
return a+b ✅ 正确 - 函数实现正确。更好的写法:
def add(a, b): # 函数名应该更具体,类型注解是可选的
return a + b理由: 函数名应该更具描述性,在Python中类型注解是可选的,但建议使用以增加代码可读性
What is the difference between a list and a tuple?
A: tuple is only-readable ,but you can check a list or change any item in it, to define a list ,you should use [],but tuple is () ✅ 正确 - 基本解释正确。补充说明:
- 列表是可变的(mutable),创建用[]
- 元组是不可变的(immutable),创建用()
- 元组通常用于存储不应该改变的数据
How do you convert a string to an integer in Python?
A: use int method ,like int("string") ✅ 正确 - 使用int()函数正确。注意:如果字符串不能转换为整数,会抛出ValueError异常
掌握情况: ✅ 良好
- 正确理解了f-string格式化输出
- 对基本数据类型有清晰认识
- 理解了变量命名规范(虽然仍有改进空间)
学习建议:
- 继续练习不同类型的数据转换
- 加强对Python类型系统的理解
掌握情况:
- 正确理解了比较操作符(==, !=)
- 对"正数"的定义有误解(认为0是正数)
- if语句语法掌握不熟练
学习建议:
- 明确正数、负数、0的概念
- 练习更复杂的条件表达式
- 学习使用if-elif-else结构
掌握情况:
- while循环实现正确
- for循环的range()使用有错误
- 缺少冒号等语法细节
学习建议:
- 深入理解range()函数的工作原理
- 练习嵌套循环
- 学习break和continue的用法
掌握情况: ✅ 良好
- 列表创建和操作基本正确
- 正确理解了列表和元组的区别
- 字典访问方法掌握正确
学习建议:
- 学习更多列表方法(extend(), insert()等)
- 练习字典的更多操作
掌握情况: ✅ 良好
- 函数定义语法正确
- 理解了参数传递
- 类型注解使用正确
学习建议:
- 练习默认参数、关键字参数
- 学习函数返回多个值
- 练习lambda函数
得分:14/20 = 70% 评价: 基础知识掌握较为扎实,但在语法细节和概念理解上还有提升空间。建议重点练习循环结构和条件判断的细节。
错题统计: 6题错误,主要分布在:
- 运算符理解(3题)
- 语法细节(2题)
- 概念理解(1题)