0% found this document useful (0 votes)
3 views17 pages

Python Programming Concepts and Structures

The document presents 10 questions about the Python programming language and relational databases. The questions cover topics such as conditional structures, search algorithms, classes, modules, CRUD, and basic operations with SQLite.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

Python Programming Concepts and Structures

The document presents 10 questions about the Python programming language and relational databases. The questions cover topics such as conditional structures, search algorithms, classes, modules, CRUD, and basic operations with SQLite.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SIMULATED - Programming Language

1) Flow control in a program refers to the logical order of execution of the commands that the
comprise, as well as the deviations in that order necessary due to certain conditions that may occur
(BANIN, p. 49, 2018)

The following code is an implementation in Python.


if value <= 1830.29:
value -= value * 0.08
elif value <= 3050.52:
value -= value * 0.09
elif value <= 6101.06:
value -= value * 0.11
Considering the provided code, indicate the alternative that correctly describes what it represents.

Alternatives:

a) A simple conditional structure, where a discount will be applied depending on the value.
b) A simple conditional structure, where an increase will be applied depending on the value.
c) A chained conditional structure, where a discount will be applied depending on the value.
d) A loop structure, which will apply an increment depending on the value.
e) A chained conditional structure, which will apply an increase depending on the value.

2) The linear search is the simplest search algorithm, it traverses the entire collection comparing the
a key with the value of the element in each position. The _____________ search is efficient for a structure.
of ordered data.
Select the option that correctly completes the gap:

Alternatives:

a) sequential; merge sort;


b) binary; sequential;
c) sequential; binary;
d) merge sort; sequential;
e) bubble sort; sequential;

The mission of the Python Software Foundation is to promote, protect, and advance the programming language.
Python, in addition to supporting and facilitating the growth of a diverse and international community of
Python programmers.

The following code is an implementation in Python.


if value <= 1830.29:
value -= value * 0.08
elif value <= 3050.52:
value -= value * 0.09
elif value <= 6101.06:
value -= value * 0.11

Considering the code presented, evaluate the following assertions:

I. The decision structure presents a condition to apply a discount on an amount.


II. The second condition of the decision structure encompasses values between 1830.29 and 3050.52.
III. The third condition of the decision structure encompasses values between 3050.52 and 6101.05.
Choose the correct option.

Alternatives:

a) Only assertions I and II are correct.


b) Only assertions II and III are correct.
c) Only assertions I and III are correct.
d) All assertions are correct.
e) Only assertion I is correct.

A store needs to implement a solution to calculate the discount on the customer's purchase. If the customer
make a purchase up to R$ 100, the discount will be 3%. If the purchase is up to R$ 500, the discount will be
10%, if it is up to a thousand, the discount will be 20%.

To implement in Python, it is necessary to follow the following steps:

1. elif value <= 500:


2. if value <= 100:
3. value -= value * 0.03
4. elif value <= 1000:
5. value -= value * 0.10
6. value -= value * 0.20
7. def calculate_discount():
8. return value
Select the option that presents the correct sequence.

["Alternatives:"]

7-3-2-5-1-6-4-8
b) 2 - 3 - 1 - 5 - 4 - 6 - 7 - 8
c) 2 - 3 - 1 - 5 - 4 - 6 - 8 - 7
d) 7 - 2 - 3 - 1 - 5 - 4 - 6 - 8
e) 7 - 1 - 5 - 6 - 4 - 3 - 2 - 8

5) In the last 3 years, the PSF has been working on donation-funded projects to improve the
internal systems and platforms. This work was carried out with the Packaging Working Group and focused on
PyPI and pip ecosystem. In this way, it was possible to show that the application of targeted funding to
open source projects have the ability to drastically increase the speed of development and
to advance our community in a much more sustainable way than relying solely on efforts
volunteers (Holscher, 2020).

The following code is an implementation in Python.

def my_function(value):
for i, c in enumerate(valor):
if [Link]() == 'a' or [Link]() == 'e':
print(c, i)
else:
continue
Considering the code presented, mark the option that correctly describes what it represents.

Alternatives:

a) A function that counts how many vowels 'a' and 'e' exist in a string.
b) A function that checks if a certain value is an integer or a character.
c) A function that locates and displays the position of each vowel 'a' or 'e', regardless of whether it is uppercase or lowercase.
lowercase.
d) A function that only locates the lowercase vowels 'a' or 'e'.
e) A function that locates and displays the position of lowercase vowels 'a' or 'e' and counts them.
amount found.

6) About classes and methods in Python, analyze the following statements:


I. A class is a way to organize data and functionalities;
II. The constructor is a reserved method called _init_;
III. In the constructor, the self parameter is mandatory and the others are defined by the programmer.
Choose the correct option

Alternatives:

a) Only assertion II is correct.


b) Only assertion III is correct.
c) Only assertions I and II are correct.
d) Only assertions II and III are correct.
e) All the assertions are correct.

7) Regarding modularity in Python, analyze the following statements:

I- When the module is imported, all the commands in it are executed.

A module can contain both executable instructions and definitions of functions and classes.

III- It is not possible to create new modules, only to use those that the language offers.
Select the correct alternative:

Alternatives:

a) Only assertions I and II are correct.


b) All statements are correct.
c) Only statements II and III are correct.
d) Only assertion I is correct.
e) Only assertion III is correct.

The relational approach represents a way of describing the database through concepts.
simple mathematics: Set Theory. Aimed mainly at improving the understanding of data by
users, this approach makes users see the database as a set of tables
two-dimensional, originated from rows and columns. The main concept comes from Set Theory linked
the conception that it is not relevant for the user to know where the data is or how the data is
(transparency) (MACHADO, p. 38, 2020).

Based on the SQLite relational database mechanism in Python, evaluate the following assertions.
I. CRUD is an acronym for the four DDL operations we can perform on a table in the database.
data
II. The first letter of CRUD - "C" stands for CREATE and pertains to the operation of creating new databases.
relational data.
III. The second letter of CRUD - 'R' stands for READ and is related to the SELECT statement of SQL.
Select the correct alternative.

Alternatives:

a) Only assertion III is correct.


b) Only assertions I and II are correct.
c) All assertions are correct.
d) Only assertions II and III are correct.
e) Only assertions I and III are correct.

9) The objective of a data model is to ensure that all existing data objects in
determined context and required by the application and the database are fully represented
and accurately. The data model must also be detailed enough to be used by
database implementer (DBA) of the database as a kind of photocopy to build the database
Physical. All the information in the logical data model will be used to define the tables of a
relational database, primary keys and foreign keys, stored procedures
procedures) and triggers (MACHADO, p. 17, 2020).

Considering the SQLite relational database mechanism in Python, evaluate the following statements.
(V) True or (F) False.

I. The [Link]() command is used to capture the rows in a table, resulting from a
SQL SELECT statement.
II. ( The command result = [Link]() stores in the variable 'result' a list of tuples, in which
each tuple is a row in the database table.
III. ( The for loop can be used to iterate over each captured record with the
[Link]().
Select the correct alternative.

Alternatives:

V-V-V
b) V - F - F
c) V - V - F
d) F - V - V
e) F - F - V

10) All attributes (columns) of a relation must be atomic, that is, indivisible in terms of
values and components. This means that there are no subgroup type columns; all are items.
elementary, not subdivided under any circumstances and where the existence of multiple is also not permitted.
occurrence of values (multivaluation) in none of its attributes (columns). It is important to understand
that each line of a table represents an object, a subject that is described by the values of each one
of these columns. Domain represents the set of admissible atomic values of a component (column)
from a relationship (table) (MACHADO, p. 42, 2020)

Para fazer uma operação READ em um banco é necessário seguir os seguintes passos:
1. import sqlite3
2. cursor = [Link]()
3. [Link](query)
4. print(line)
5. resultado = [Link]()
6. conn = [Link]('my_database.db')
7. for line in result:
8. query = "SELECT * FROM fornecedor"
Select the option that presents the correct sequence.

Alternatives:
a) 1 - 3 - 5 - 4 - 7 - 2 - 8 - 6
b) 1 - 6 - 2 - 8 - 3 - 5 - 7 - 4
c) 8 - 7 - 6 - 3 - 1 - 5 - 2 - 4
d) 1 - 5 - 2 - 3 - 7 - 8 - 6 - 4
e) 1 - 8 - 7 - 3 - 2 - 5 - 4 - 6

Unit 1

1) Variables are spaces allocated in memory _______, to temporarily store values. In Python,
these spaces do not need to be _________, that is, the variable can be allocated without specifying the ________
that she will wait. The Python interpreter is able to determine the data type of the variable based on its
_____, that is, the variables are typed _________ in this language.
Choose the option that correctly fills in the blanks.

Alternatives:

a) RAM; specified; value; value; dynamically


b) RAM; tipados; tipo de dado; valor; dinamicamente
c) RAM; specified; value; value; randomly
d) RAM; tipados; tipo de dado; valor; aleatoriamente
e) cache; typed; value; value; dynamically

2) To know the type of data that a variable holds, the Python interpreter relies on the function type().

The following code represents variable creation in the Python language.


x = 10
nome = 'aluno'
nota = 8.75
fez_inscricao = True

The following code represents the use of the function type()


1. print(type(x))
2. print(type(name))
3. print(type(note))
4. print(type(fez_inscricao))
Choose the option that represents the output of the commands from lines 1 to 4.

Alternatives:

a)

int
str
float
bool

b)

integer
str
decimal
bool

c)
float

str
decimal
bool

d)

integer
string
float
string

e)

float
string
float
string
3) The Python programming language supports the four basic mathematical operations, in addition to others. The
the following code is a snippet of a program in Python.

1. x = 4
2. y = 5
3. print(x / y)
4. print(x // y)
Considering the code snippet in Python, choose the option that represents what will be printed by
lines 3 and 4.

Alternatives:

The values 4 (line 3) and 5 (line 4) will be printed.


The values 5 (line 3) and 4 (line 4) will be printed.
The values 0 (line 3) and 1 (line 4) will be printed.
d) The values 0.8 (line 3) and 0 (line 4) will be printed.
e) The values 0 (line 3) and 0.8 (line 4) will be printed.

The condition for a student to pass is to have a final average of 7 points or higher. This condition can be
implemented in the Python language, through a conditional structure.
Considering the Python language, choose the option that correctly implements the condition for the student.
to be approved.

Alternatives:
a)

if media_final > 7:
approved

b)

elif media_final >= 7:


approved

c)

if media_final >= 7:
approved

d)

if media_final < 7:
approved

e)

elif media_final < 7:


approved

Python was released in the early _____ by _______ van Rossum at the Stichting Mathematisch
Centrum (CWI), in the Netherlands, as the successor of a language called _______. ________ is the main
author of Python, although it includes many contributions from other researchers.
Choose the option that correctly completes the gaps.

Alternatives:

a) 70; Guido; PSF; Guido


b) 80; Mark; HIJ; Mark
c) 90; Guido; ABC; Guido
d) 90; Mark; ABC; Mark
e) 80; Guido; ABC; Guido

6) Python is a programming language ______ clear and powerful that uses a ________ elegant,
making it easier to read the programs you write. Comes with a great _______ standard that supports
many common programming tasks, such as connecting to web servers, searching for text with
regular expressions, read and modify files.
Choose the option that correctly completes the blanks.
Alternatives:

a) object-oriented; syntax; library


b) structural; syntax; interface
["c) procedural","interface","library"]
d) object-oriented; interface; library
e) structural; interface; library

One of the great characteristics of language is its _________. One of Guido's main ideas is
that the code is _______ much more often than it is ________. Such an aspect is so relevant that,
A piece of code that follows the rules of the Python language is called a "___________." These rules are defined
by _______ (Python Enhancement Proposal) and relate to formatting, indentation, parameters in
functions, and everything else that may be related to code syntax.
Choose the option that correctly fills in the blanks.

Alternatives:

["syntax","written","specified","pythonic code","PEP 8"]


b) interface; lido; escrito; python code; PEP 8
c) interface; read; written; python code; PEP 10
d) sintaxe; lido; escrito; pythonic code; PEP 8
e) syntax; read; written; python code; PEP 8

There are several elements that are part of programming techniques, regardless of the language.
programming. Figure 1 presents an element of programming.

Figure 1 - Programming element.

Source: GRIFFITHS and BARRY, p. 13, 2009.


Choose the option that contains the programming technique illustrated in Figure 1.

Alternatives:

a) Loop structure.
b) Decision structures.
c) Function.
d) Recursion.
e) Modules.
Unit 2

1) Objects of type ________ are data structures capable of storing _______ value. These
data structures represent sequences ______ indexed by numbers __________.
Choose the option that correctly completes the blanks.

Alternatives:

a) sequence - more than one - finite - non-negative


b) list - more than one - infinite - negatives
c) sequence - one - infinite - non-negative
d) list - a - infinite - negatives
e) tuples - more than one - infinite - non-negative

2) The first element of a sequence occupies ____, the second 1, the last element occupies the position
______, where n is the capacity of ________ of the sequence. Some operations that can be performed with
sequences in Python are: in, ____, sum (+), among others.
Choose the option that correctly completes the blanks.

Alternatives:

a) the index -1 / n - 1 / storage / none in


b) the index 0 / n / growth / not in
c) the index -1 / n / storage / none in
d) the index 0 / n - 1 / storage / not in
e) the index 0 / n - 1 / growth / none in

3) A text is an object of the class _____, which is a type of ________. Objects of the str class have
certain operations, such as, in, _____, among others. This type of object is _________, that is, it does not
it is possible to assign a new value to a _________.
Choose the option that correctly fills in the blanks.

Alternatives:

a) string / list / not in / immutable / specific position


b) str / sequence / not in / immutable / specific position
c) string / list / none in / mutable / specific position
d) string / list / none in / immutable / variable
e) str / tuple / not in / immutable / specific position

4) The notation _______, represents a _________ complexity, that is, the execution time will increase.
linearly with the size of the input. Other complexities that are commonly encountered are:
O(log N), O(N2), O(N3). It is worth noting that in terms of efficiency we will have: O(1) < O(log N) < _____ <
O(N2) < O(N3) < O(2N) that is, an algorithm with O(N) complexity is more efficient than _______.
Choose the option that correctly fills in the blanks.
Alternatives:

a) F(N) / linear / O(10) / O(N2)


b) O(N) / linear / O(N) / O(N2)
c) O(N) / quadratic / O(log N)2) / O(log N)
d) F(N) / quadrática / O(N) / O(log N)
e) O(N) / linear / O(N) / O(log N)

5) All _______ in a Python program are represented by __________ or by the relationship between
objects. Everything in Python is an ________, that is, it is a structure that has certain characteristics and
________.
Choose the option that correctly fills in the blanks.

Alternatives:

a) commands - functions - object - attributes.


b) data - objects - object - actions
c) commands - functions - object - actions.
d) data - objects - object - attributes.
e) data - lists - object - actions.

6) A _______ can be more _______ than a primitive type, for example, the type ________ int, in the
The C language occupies a maximum of 4 bytes (32 bits) and can store values between -2,147,483,648 and
2,147,483,647. On the other hand, the int type object in the Python language does not have a defined limit; such an object remains
limited only to the available memory ______ in the environment.
Choose the option that correctly fills in the blanks.

Alternatives:

a) data - simple - primitive - RAM


b) object - simple - compound - ROM
c) object - complex - primitive - RAM
d) object - complex - composite - ROM
e) given - complex - primitive - RAM

The type of the ______ determines the values it can store and the ______ that can be made with it.
In such structure, for example, the class _____, in languages like C, a string is an array of the primitive type.
_______, already in Python, this object, besides having unlimited size, has several _______ for manipulation of
texts, such as split(), replace(), among others.
Choose the option that correctly fills in the blanks.

Alternatives:

a) dado - funções - int - char - contêiners


b) given - functions - str - char - methods
c) object - strings - str - string - containers
d) given - operations - str - char - methods
e) object - operations - str - char - methods

Computational _______ are developed and used to solve various problems, in this
universe, as the name suggests, _____ algorithms solve problems related to _____ values in
a _________.
Choose the option that correctly fills in the blanks.

Alternatives:

a) software - sorting - finding - data structure


b) algorithms - sorting - finding - variable
c) softwares - busca - encontrar - variável
d) algorithms - search - find - data structure
e) algorithms - search - sort - data structure

Unit 3

1) Objects are the components of an OO program. A program that uses OO technology is basically
a collection of _______. A ______ is a model for an object. We can consider a ________,
as a way to organize the data (of an object) and its ____________.
Choose the option that correctly fills in the blanks.

Alternatives:

a) objects; function; class; attributes


b) classes; classe; função; comportamentos
c) objects; class; function; attributes
d) objects; class; class; behaviors
e) classes; data structure; class; behaviors

2) Let's think about the construction of a house, before the "house object" exists, an architect made the blueprint,
determining everything that should be part of that object. Therefore, the _____ is the model and the ______ is a
______. Instance refers to the physical existence, _________, of the object.
Choose the option that correctly completes the blanks.

Alternatives:

a) class; attribute; characteristic; in memory


b) function; method; specialization; of the characteristics
c) class; object; specialization; in memory
d) object-oriented; object; instance; of the characteristics
e) class; object; instance; in memory

3) The data stored in an object represents the state of the object. In programming terminology
Oh, this data is called ________ and it contains the ___________ that differentiate the various
objects. The ________ of an object represents what the object can do. In procedural languages, the
behavior is defined by procedures, functions, and subroutines. In OO programming terminology,
these behaviors are contained in the ________.
Choose the option that correctly fills in the blanks.

Alternatives:

a) atributos; informações; comportamento; métodos


b) objects; characteristics; method; objects
c) attributes; variables; behavior; objects
d) objects; information; constructor method; methods
e) attributes; information; method; constructors

4) The development of software involves good programming practices. In Python, all imports
they must remain in the _______ of the file. According to the documentation, it is good practice to declare first the
libraries ______, followed by the libraries _______ and finally, _______ created for the application. Each
block must be separated by a blank line.
Choose the option that correctly fills in the blanks.

Alternatives:

a) beginning; from third parties; standard; the specific modules


b) final; standard; third parties; the specific modules
c) start; standard; from third parties; the specific modules
d) start; pattern; built-in; third-party modules
e) final; standard; built-in; third-party modules

5) As __________ change very quickly in the software industry, while the concepts __________.
Therefore, it is necessary to understand the concepts in order to _________ in the technology adopted by the company (and this
technology can change ___________) (Weisfeld, 2013).

technologies; evolve; implement them; quickly


Choose the option that correctly completes the blanks.

Alternatives:

a) technologies; evolve; implement them; quickly


b) programming languages; evolve; implement them; quickly
c) technologies; evolve; implement them; slowly
d) programming languages; do not change; implement them; quickly
e) programming languages; do not change; to adapt them; quickly

6) Software development ________ has existed since the early 1960s, but it was only in
the mid-____ decade that the object-oriented paradigm began to _______ (Weisfeld, 2013).
Choose the option that correctly fills in the blanks.

Alternatives:

a) structured; 90; gain momentum


b) object-oriented; 90; gain momentum
c) object-oriented; 80; to be used
d) structured; 80; to be used
e) structured; 70; gain momentum

7) Object-oriented software development (OO) has existed since the early 1960s, but it was
Only in the mid-1990s did the object-oriented paradigm begin to gain momentum. A
a language is considered object-oriented if it applies the concept of __________ and supports the
implementation of _________, of __________ and of polymorphism.
Choose the option that correctly fills in the blanks.

Alternatives:

["abstraction","function","inheritance"]
["function","encapsulation","inheritance"]
["abstraction","encapsulation","inheritance"]
["encapsulation","inheritance","method"]
e) attributes; method; class

A solution may start with a few lines of code, but soon become hundreds.
thousands and even millions of lines. In this scenario, working with a single flow of code becomes unfeasible,
giving rise to implementation techniques to organize the solution. One option to organize the code is
implement in ________, thus each block is responsible for a certain functionality. Another
the way is to use __________ and create classes that encapsulate the characteristics and behaviors of a
determined ________.
Choose the option that correctly fills in the blanks.

Alternatives:

a) funções; orientação a objetos; objeto


b) files; object-oriented; event
["functions","functional programming","object"]
d) files; functional programming; object
e) functions; object-oriented; event
Unit 4

1) To use the pandas library, you need to install it using the command: pip install ________.
As a high-level tool, pandas has two data structures that are the main ones for the
data analysis/manipulation: a Series and the DataFrame. A Series is like ______________, capable of
store different types of data. A DataFrame is ___________, or as the documentation presents,
a container for Series.
Choose the option that correctly fills in the gaps.

Alternatives:

a) PyPI; a matrix; a vector.


b) pandas; a matrix; a vector.
c) PyPI; a data vector; a set of Series
d) pandas; a data vector; a column
e) pandas; a vector of data; set of Series

To construct an object of the DataFrame type, we need to use the _________ method from the pandas package.
Among all the expected parameters, only one is mandatory to create a DataFrame with data, the
parameter ________. This parameter can receive an iterable object, such as a list, tuple, ________ or
a DataFrame.
Choose the option that correctly fills in the blanks.

Alternatives:

a) DataFrame(); data; a dictionary


b) construct(); data; string
c) DataFrame(); columns; string
d) construct(); columns; a dictionary
e) DataFrame(); columns; a dictionary

3) CSV (comma-separated values) is a file format in which data is separated by


____________. Originally, this delimiter is __________, but in practice a CSV file can be
created with any delimiter, for example, by semicolon (;), by pipe (|), among others. Because it is a
File ________, is easy to be read on any system, which is why it has become so democratic.
Choose the option that correctly fills in the blanks.

Alternatives:

a) delimitador; vírgula; tab; chave/valor


b) comma; comma; tab; text
c) comma; a delimiter; a comma; of text
d) delimiter; tab; a comma; key/value
e) comma; a delimiter; a comma; key/value
4) Among the various libraries available in the repository _________, pandas is a Python package that
provides data structures designed to facilitate work with data ___________ (tables) and series
temporals ([Link] This package started to be
developed in 2008, becoming an open source solution at the end of 2009. Since 2015, the project
_______ is sponsored by NumFOCUS.
Choice a option what complete correctly as gaps.

Alternatives:

a) PyPI; structured; pandas


b) Git; structured; pandas
c) PyPI; unstructured structured; PyPI
d) Git; unstructured structured; PyPI
e) PyPI; structured; Python

Databases in general do not contain all possible information about something stored there. A
data is an organized form of information, but it occurs as long as specific fields are
filled in so that their recovery occurs automatically (IIMA, 2015).
Regarding data storage in files, choose the correct option.

Alternatives:

a) Unstructured data are data that contain an organization for retrieval.


b) Structured data are data that contain an organization for retrieval.
c) A delimited file, for example, with a csv extension is an unstructured file.
A file with a json extension is an unstructured file.
e) Unstructured files can be read and stored in a DataFrame from the library
pandas, without any treatment, as the library was created for that.

6) A library created to work with data needs __________ that supports storage and
manipulation. The Python language has some structures that are already part of its standard interpreter,
such as the _________, capable of storing a sequence of values and increasing or decreasing
your capacity according to the need, or else the __________, which are structures that store the
data in key-value format.
Choice a option what complete correctly as gaps.

Alternatives:

a) data structures; tuples; dictionaries


b) methods; lists; json
c) data structures; lists; json
d) data structures; lists; dictionaries
e) methods; lists; dictionaries
7) The pandas library was developed to work with _____________ data, that is, data arranged
in rows and columns. The data can be stored in files, on web pages, in APIs, in others
softwares, in ________ (cloud storage systems) or in databases. For all these
origins (and even more), the library has __________ capable of reading the data and loading
____________.
Choose the option that correctly completes the blanks.

Alternatives:

a) unstructured; object stores; methods; in a DataFrame


b) structured; DBMS; functions; in a dictionary
c) unstructured; DBMS; functions; in a dictionary
d) structured; object stores; methods; in a DataFrame
e) structured; object stores; methods; in a dictionary

You might also like