Quiz: Python Basics and Math Functions — 13 perguntas

Perguntas e respostas detalhadas

1. What does Python display when it executes `print(2+5)`?

An error message
The number 7
The text `25`
The text `2+5`

The number 7

Explicação

`print()` evaluates expressions before displaying them, so `2+5` is calculated and the output is 7. Writing `print("2+5")` would display the expression as text instead.

2. Which type of Python string can contain line breaks directly within its delimiters?

A numeric string
A triple-quoted string
A double-quoted string
A single-quoted string

A triple-quoted string

Explicação

Triple-quoted strings can span multiple lines, whereas single- and double-quoted strings are generally used for single-line strings.

3. What value does `abs(-4)` return?

-4
4
0
An error because the number is negative

4

Explicação

The `abs()` function returns a number's absolute value, so `abs(-4)` returns 4 rather than preserving the original negative sign.

4. What does `pow(2,6)` calculate?

The sixth root of 2
2 raised to the sixth power
The product of 2 and 6
The sum of 2 and 6

2 raised to the sixth power

Explicação

`pow(a,b)` calculates a raised to the power of b. Therefore, `pow(2,6)` is 2⁶, which equals 64.

5. What does `round(3.14159, 2)` return?

3.14
3
3.14159
3.1

3.14

Explicação

The second argument of `round()` specifies the number of decimal places, so the value is rounded to two places as 3.14.

6. Which expression correctly calls the square-root function after executing `import math`?

`math->sqrt(25)`
`import.sqrt(25)`
`math.sqrt(25)`
`sqrt(25)`

`math.sqrt(25)`

Explicação

`import math` loads the module and requires its functions to be accessed with the `math.` prefix, making `math.sqrt(25)` correct. The unqualified form `sqrt(25)` requires a direct import.

7. Which statement correctly uses names imported with `from math import factorial, pi, log2`?

`factorial(5)`
`math->factorial(5)`
`module.factorial(5)`
`math.factorial(5)`

`factorial(5)`

Explicação

A direct import places the selected names in the local namespace, so `factorial(5)` can be called without the `math.` prefix. Using `math.factorial(5)` corresponds to importing the module as `import math`.

8. How does an interpreter differ from a compiler when processing a Python program?

An interpreter processes and executes code line by line, while a compiler processes the program before execution
An interpreter displays code in an editor, while a compiler executes it in a terminal
An interpreter translates only mathematical expressions, while a compiler translates only text
An interpreter processes the entire program before execution, while a compiler runs code line by line

An interpreter processes and executes code line by line, while a compiler processes the program before execution

Explicação

An interpreter processes and executes code during execution, typically line by line. A compiler processes the program before it runs.

9. Which Visual Studio Code action runs a Python file without starting a debugging session?

Toggle Terminal using Ctrl+backtick
Run Without Debugging using Ctrl+F5
Format Document using Shift+Alt+F
Open File using Ctrl+O

Run Without Debugging using Ctrl+F5

Explicação

In Visual Studio Code, Run Without Debugging executes the Python file without launching a debugging session. Ctrl+F5 is the corresponding shortcut.

10. What is the primary purpose of a Python library?

To provide reusable functions and tools for a particular purpose
To display Python code without executing it
To convert all Python programs into web applications
To replace every individual function with a single command

To provide reusable functions and tools for a particular purpose

Explicação

A Python library is a collection of ready-made, reusable code that provides functions or tools for a particular purpose. A single function is just one callable operation within or outside a library.

11. Which pairing correctly matches a Python library with its main application?

Matplotlib for machine learning and scikit-learn for visualization
NumPy for web development and Django for calculations
NumPy for calculations and Matplotlib for data visualization
Django for calculations and pandas for deep learning

NumPy for calculations and Matplotlib for data visualization

Explicação

NumPy is associated with numerical calculations, while Matplotlib is used for data visualization. The other pairings assign libraries to applications they are not primarily associated with here.

12. Which formulas correctly calculate the circumference and area of a circle with radius 5?

C = 2π × 5 and A = π × 5²
C = π × 5 and A = 2π × 5²
C = π × 5² and A = 2π × 5
C = 4 × 5 and A = 5²

C = 2π × 5 and A = π × 5²

Explicação

A circle’s circumference uses C = 2πr, whereas its area uses A = πr². Substituting r = 5 gives the stated formulas.

13. A program needs to calculate both measurements of a square whose side length is 5 units. Which pair of expressions produces its perimeter and area, respectively?

5² and 4 × 5
4 × 5 and 5²
5 + 5 and 4 × 5²
4 + 5 and 5 × 5

4 × 5 and 5²

Explicação

A square’s perimeter is found with 4s, giving 20 units, while its area is found with s², giving 25 square units. The formulas must not be reversed.

Revisar com flashcards

Memorize as respostas com 36 flashcards sobre Python Basics and Math Functions.

What does the print() function display in Python output?

Text, numbers, and evaluated expressions.

Which quote styles can Python strings use?

Single, double, or triple quotes.

What can triple-quoted strings do that single or double quotes cannot?

Span multiple lines.

Veja os flashcards →

Estude a ficha de revisão

Leia a ficha de revisão completa sobre Python Basics and Math Functions.

Veja a ficha de revisão →

Similar courses

Crie seus próprios quizzes

Importe seu curso e a IA gera quizzes com correções em 30 segundos.

Gerador de quizzes