跳至主要內容

UIC All QUIZ 模拟考

AI悦创原创Python 一对一教学uicUIC Information SpacecodingbatPython 一对一教学uicUIC Information Spacecodingbat大约 11 分钟...约 3179 字

UNITED INTERNATIONAL COLLEGE

Each question is worth 2 points. Only 1 answer is correct. Report your answer in the last page

每道题2分。只有一个答案正确。在最后一页报告你的答案

选择题

  1. Which of the following function convert a string to a float in python?

下面哪个函数在 python 中将字符串转换为浮点数?

A. int(x [,base])

B. long(x [,base])

C. float(x)

D. str(x)

  1. Which of the following is used to define a block of code in Python language?

A. Indentation

B. Key

C. Brackets

D. Colon

  1. Which of the following statement is correct?

A. “print” and “return” statements have the same effect.

B. “print” statement’s output can be used by another program’s argument.

C. “return” statement can print something out on the console.

D. “return” statement can be used in the definition of a function to produce its output.

  1. What is displayed with following Python statement?
a = 12
b = 3 
a != 12 and b == 3

A. True

B. False

C. 0

D. 12

  1. Regarding Python as a programming language, which of the following statement is incorrect?

A. Python is an interpreted language.

B. Python is a high-level, cross platform language.

C. To execute Python code, a complier is required.

D. There are extensive libraries available, such as Numpy, Requests, Matplotlib, etc.

对于 Python 编程语言,以下陈述中错误的是:

C. 执行 Python 代码,需要编译器。

A. Python 是解释型语言。这是正确的。解释型语言是一种不需要编译就可以执行的编程语言。Python 代码通常在运行时解释和执行。

B. Python 是高级的、跨平台的语言。这也是正确的。作为一种高级语言,Python 用简洁的语法实现了许多复杂的功能。并且,Python 是跨平台的,可以在多种操作系统(如 Windows、Linux、Mac OS 等)上运行。

C. 执行 Python 代码,需要编译器。这是错误的。Python 是一种解释型语言,不需要编译器。Python 代码通常由 Python 解释器在运行时解释并执行。尽管有一些工具可以将 Python 代码编译为二进制代码或机器代码,但这并不是执行 Python 代码的必要条件。

D. Python 提供了众多的库,如 Numpy、Requests、Matplotlib 等。这是正确的。Python 有着庞大的库资源,它们可以帮助我们更方便地进行编程,例如进行数值计算(Numpy)、发出 HTTP 请求(Requests)、创建图表(Matplotlib)等。

Python常用的库50个

下面是 50 个常用的 Python 库,这些库覆盖了数据科学、网络开发、自动化、Web 爬虫、图像处理、机器学习等多个领域:

  1. NumPy: 用于数值计算。
  2. Pandas: 用于数据分析和处理。
  3. Matplotlib: 用于创建静态、动态和交互式的可视化图表。
  4. Seaborn: 基于 Matplotlib 的数据可视化库。
  5. Scikit-Learn: 用于机器学习。
  6. TensorFlow: 用于深度学习。
  7. Keras: 基于 TensorFlow 的深度学习库。
  8. PyTorch: 用于深度学习。
  9. OpenCV: 用于计算机视觉。
  10. NLTK: 自然语言处理库。
  11. Spacy: 另一种自然语言处理库。
  12. BeautifulSoup: 用于解析 HTML 和 XML 文档,常用于 Web 爬虫。
  13. Scrapy: 强大的 Web 爬虫框架。
  14. Requests: 用于发送 HTTP 请求。
  15. Flask: 轻量级的 Web 框架。
  16. Django: 重量级的 Web 框架。
  17. Tornado: 异步 Web 框架和网络库。
  18. SQLAlchemy: SQL 工具包和对象关系映射(ORM)系统。
  19. Pygame: 用于游戏开发。
  20. Pillow: 用于图像处理。
  21. PyQT / Tkinter / wxPython: 用于创建 GUI。
  22. SciPy: 用于科学计算。
  23. Plotly: 用于创建复杂的交互式图表。
  24. Statsmodels: 用于统计和经济学算法。
  25. Bokeh: 用于创建交互式图表。
  26. NetworkX: 用于创建、操作和研究复杂网络的结构、动态和功能。
  27. SymPy: 用于符号数学。
  28. PySpark: 用于处理大数据。
  29. Biopython: 用于生物信息学。
  30. Astropy: 用于天文学。
  31. Gensim: 用于文本挖掘。
  32. Twisted: 用于异步网络编程。
  33. Selenium: 用于自动化 Web 浏览器交互。
  34. Cython: 用于编写 C 扩展的 Python。
  35. PyCrypto / Cryptography: 用于密码学。
  36. Pymongo: MongoDB 的 Python 驱动程序。
  37. Redis / Celery: 用于任务队列。
  38. Fabric: 用于系统管理。
  39. Robot Framework: 用于自动化测试。
  40. elasticsearch-dsl-py: Elasticsearch 的官方高级 Python 客户端。
  41. Pytest: 用于编写测试。
  42. PyYaml: 用于处理 YAML 数据。
  43. Pendulum: 用于处理日期和时间。
  44. Click: 用

于创建命令行界面。
45. Pyglet: 用于多媒体和窗口应用的开发。
46. PyOpenGL: 用于渲染3D图形。
47. Numba: 用于加速 Python 代码的库。
48. Dask: 用于并行计算。
49. FastAPI: 构建 API 的现代、快速(高性能)的 web 框架。
50. Dash: 用于创建分析性 web 应用的库。

这些只是 Python 提供的众多库中的一部分,每一个库都有其自己的特定用途,可以根据具体的任务需求来选择合适的库。

  1. Python supports the creation of anonymous functions at runtime, using a construct called?

A. lambda

B. pi

C. anonymous

D. none of the mentioned

  1. What will be displayed with the following Python code?
y = 6 
z = lambda x: x%y
print(z(8))

A. 2

B. 75%

C. 125%

D. 1

  1. What will be displayed with the following Python code?
def f(x, y, z):
    return x + y + z
f(2, 30, 400)

A. 432

B. 24000

C. 430

D. No output

  1. Which of the following statement is correct?

A. We shall always define a global variable in our program.

B. We shall define anonymous functions whenever it is possible.

C. A function may be defined without any arguments.

D. Functions shall be named as simple as possible.

  1. What will be displayed with the following Python code?
x = "abcdef"
while i in x:
    print(i + " ")

A. a b c d e f

B. abcdef

C. i i i i i i …

D. error

  1. What will be displayed with the following Python code?
x = 'abcd'
for i in range(len(x)):
    print(i)

A. a b c d

B. 0 1 2 3

C. error

D. 1 2 3 4

  1. What will be displayed with the following Python code?
for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

A. 0 1 2 3 4 Here

B. 0 1 2 3 4 5 Here

C. 0 1 2 3 4

D. 1 2 3 4 5

详情

这段 Python 代码首先是一个带有 else 语句的 for 循环。代码的工作原理是这样的:

首先,for 循环会在 range(10) 中进行迭代,也就是说,它会循环遍历这些数:0, 1, 2, 3, 4, 5, 6, 7, 8, 9。

对于每一个数 i,代码会首先检查 if i == 5 是否为真。如果 i 等于 5,那么 break 语句就会被执行,这会立即结束 for 循环,即使还有未遍历的元素。如果 i 不等于 5,那么 else 语句就会被执行,print(i) 会打印出当前的 i

最后,else 语句也是 for 循环的一部分,这可能有点令人困惑,因为在许多语言中,else 语句只与 if 语句一起使用。然而,在 Python 中,else 语句可以与 forwhile 循环一起使用。在这种情况下,else 语句中的代码块会在循环正常结束时执行。但是,如果循环是由 break 语句中断的,那么 else 语句中的代码就不会执行。

所以,这段代码会打印出 0 到 4 的数字,然后在 i 等于 5 时停止。因为循环是由 break 语句中断的,所以 print("Here") 不会被执行。

  1. Which of the following is a Python tuple?

A. {1, 2, 3}

B. {1:10, 2:20, 3:30}

C. [(1, 2), (2, 3), (3, 4)]

D. ([1, 2], [2, 3], [3, 4])

  1. In order to store values in terms of key and value we use what core data type?

A. list

B. tuple

C. class

D. dictionary

  1. What will be displayed with the following Python code?
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))

A. 1

B. Error, invalid syntax for formation of set

C. 4

D. 8

  1. Which of the following is NOT an advantage of using modules?

A. Provides a means of reuse of program code

B. Provides a means of dividing up tasks

C. Provides a means of reducing the length of the program code

D. Provides a means of testing individual parts of the program

  1. Which of the options below could possibly be the displayed with the following program? [hint:randrange(start, stop, step) method returns a randomly selected element from the specified range]
from random import randrange
L = list()
for x in range(5):
    L.append(randrange(0, 100, step=2) - 10)
print(L)

A. [-8, 88, 8, 58, 0]

B. [-8, 81, 18, 46, 0]

C. [-7, 88, 8, 58, 0]

D. [-8, 88, 94, 58, 0]

详情

这段代码主要执行了以下操作:

  1. from random import randrange: 这一行从 Python 的 random 模块中导入了 randrange 函数。randrange 是一个生成指定范围内随机整数的函数。

  2. L = list(): 这一行创建了一个空的列表,并将其赋值给变量 L

  3. for x in range(5): 这一行启动一个 for 循环,循环次数为 5 次。循环变量 x 的值会在每次循环中从 0 到 4 变化。

  4. L.append(randrange(0, 100, step=2) - 10): 这一行是 for 循环的主体部分,它会在每次循环中执行。首先,randrange(0, 100, step=2) 会生成一个 0 到 100(包含 0,不包含 100)之间的随机偶数,然后从这个随机数中减去 10,得到的结果被添加(append)到列表 L 的末尾。

  5. print(L): 最后,这一行打印出列表 L 的内容。由于 L 的内容是在 for 循环中添加的,所以 L 应该包含了 5 个随机生成的、位于 -10 到 90(包含 -10,不包含 90)之间的偶数。

所以,这段代码的主要作用是生成一个包含 5 个随机偶数的列表。这些随机数在 -10 到 90 之间,然后打印出这个列表。

  1. In Python, which functions are used to accept input from the user

A. input()

B. raw_input()

C. rawinput()

D. string()

  1. Given the file dog_breeds.txt, which of the following is the correct way to open the file for reading as a text file?

A. open(‘dog_breeds.txt', ‘a’)

B. open(‘dog_breeds.txt', 'r')

C. open(‘dog_breeds.txt', 'w')

D. open('dog_breeds.txt', 'x')

  1. What will be the displayed with the following Python code?
class test:
    def __init__(self, a="Hello World"):
        self.a = a
    def display(self):
        print(self.a)
obj = test()
obj.display()
详情

这段代码定义了一个名为 test 的类,并创建了这个类的一个对象 obj。下面详细解释这段代码的每一部分。

  1. class test:: 这一行定义了一个名为 test 的新类。

  2. def __init__(self, a="Hello World"):: 这一行定义了类的初始化方法 __init__。这个方法会在创建类的新对象时自动调用。self 是一个指向类实例的引用(在其他编程语言中,可能会被称为 this)。a 是一个参数,其默认值为字符串 "Hello World"。

  3. self.a = a: 这一行创建了一个名为 a 的实例变量,并将参数 a 的值赋给它。实例变量是绑定到类的实例的变量,每个实例都有自己的实例变量。

  4. def display(self):: 这一行定义了一个名为 display 的类的方法。这个方法接受一个参数 self,即类的实例的引用。

  5. print(self.a): 这一行打印出实例变量 a 的值。

  6. obj = test(): 这一行创建了 test 类的一个新对象,并将这个对象赋值给变量 obj。由于在创建对象时没有提供任何参数,所以 a 的值将会是它的默认值 "Hello World"。

  7. obj.display(): 这一行调用 obj 对象的 display 方法,打印出实例变量 a 的值,也就是 "Hello World"。

所以,这段代码的主要作用是创建了一个类 test,这个类有一个实例变量 a 和一个方法 display。然后创建了这个类的一个对象,并调用了这个对象的 display 方法,打印出 "Hello World"。

编程题目

Exercise (15 points)

Define the function read_txt() that reads in a given .txt file and returns a list that contains all the lines from the file.

Example:

Given the test.txt file with the contents below,

line1
line2
line3
line4
line5
line6
line7

Expected Output:

['line1', 'line2', 'line3', 'line4', 'line5', 'line6', 'line7']

Hint:

  • Note that you can use strip() function to remove '\n' the newline characters.
公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQopen in new window

方法二:微信:Jiabcdefh

上次编辑于:
贡献者: AndersonHJB
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度