0% found this document useful (0 votes)
5 views15 pages

Python Programming Concepts Explained

1) Interpretation is the process of converting languages where no executable code is generated and the program runs as it is being converted. 2) Machine language has no abstraction. 3) Python is a language that supports object-oriented programming and multiple inheritance, where indentation is part of the syntax.

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)
5 views15 pages

Python Programming Concepts Explained

1) Interpretation is the process of converting languages where no executable code is generated and the program runs as it is being converted. 2) Machine language has no abstraction. 3) Python is a language that supports object-oriented programming and multiple inheritance, where indentation is part of the syntax.

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

1.

What is the name of the process of converting languages where executable code is not generated and the program runs as it is being
converted.

Assembler

Compilation

Translation

Connector

Interpretation
Data Resp.: 08/19/2022 09:59:50

Explanation:

The correct answer is: Interpretation

2. 1.

Which of the languages below has no abstraction?

Assembly language

machine language

HTML language

JAVA language

Python language
Data Resp.: 08/19/2022 10:00:46

Explanation:

The correct answer is: machine language.

BASIC PYTHON

Regarding the Python language, it is stated:


3.

I - It is a language with support for object-oriented programming and multiple inheritance.

II - It is a language where indentation is part of the syntax.

III - Has an object-oriented implementation where all attributes are mandatory private.

IV - It is a language that has static typing.

The statements are correct:

I and II.
I, III and IV.

III and IV.

II and IV.

II and III.
Data Resp.: 19/08/2022 10:01:23

Explanation:

The correct answer is: I and II.

The Python language is known for having dynamic typing, that is, the assignment of values to a variable occurs during execution.
can be changed dynamically. Its indented syntax promotes code organization and readability. Python adds the
visibility attributes present in object-oriented languages.

4. Data structures are responsible for organizing and storing data efficiently, creating ways for the user to handle them.
Widely used and known structures are stacks, lists, and queues. Regarding Algorithms and Data Structures, given the statements
below, mark the CORRECT alternative:

Python is a compilable language, which, after this process, generates an executable file of the binary type.

Python is a procedural language that does not include object-oriented programming.

Lists in Python are sets of values, which can only be of the same type, accessed by a numeric index that starts at 0.
(zero).

Variable declaration is something mandatory in Python.

In conditional or loop commands, the separation of code blocks in Python is done using indentation.
Data Resp.: 19/08/2022 10:01:42

Explanation:

The correct answer is: In conditional or looping statements, the separation of code blocks in Python is done using indentation.

Python is an interpreted language that supports object-oriented programming. In Python, it is not necessary to declare a variable before
using it, and the indentation of the code is essential between the blocks for its proper functioning

STRUCTURED PYTHON

5. Consider the following excerpt from a program written in Python:

import math

print(sqrt(36))

What will be the result of executing this program?

An error will occur because the print() function needs to receive a string as a parameter.

It will be printed on the screen: "6"

It will be printed on the screen: 6

It will be printed on the screen: 6.0


An error will occur because the correct call should be [Link](36)
Data Resp.: 08/19/2022 10:04:34

Explanation:

The correct answer is: An error will occur because the correct call should be [Link](36)

6. Observe the print function of the code written in Python below:

What is the output printed by this function?

16

32

24

20
Data Resp.: 08/19/2022 10:07:37

Explanation:

The correct answer is: 24

OBJECT-ORIENTED PYTHON

7. Analyze the following Python code.

class End_simple(object):

def __init__(self, street, number, neighborhood):

[Link] = street

[Link] = num

[Link] = neighborhood

def Address(self):

return [Link] + ", " + [Link] + " \ " + [Link]


class End_com(End_simples):

def __init__(self, street, number, neighborhood, community):

End_simples.__init__(self, street, number, neighborhood)

[Link] = com

def Address(self):

...

a = End_simples("Av Brasil", "243", "Floresta")

b = End_com("Av Miracema", "12", "Centro", "apto 3")

print([Link]())

print([Link]())

It is known that executing this code produced the following two lines.

From Brazil, 243 Forest

Av Miracema, 12 Centro, apto 3

Select the option that presents the correct definition for the method Endereco in the class End_com.

return [Link]() + ', ' + [Link]

return parent(End_com, self).Address() + ", " + [Link]

return super(End_com, self).Address() + ', ' + [Link]

return End_simples.Address() + ", " + [Link]

return [Link]() + ", " + [Link]


Data Resp.: 19/08/2022 10:09:05

Explanation:

The correct answer is: return super(End_com, self).Endereco() + ", " + [Link]

In the Endereco method of the End_com class, a call must be made to the Endereco method of its parent class, the End_simples class, which
return the values for street, number, and neighborhood as a string: return [Link] +,¿+self.νm+,¿+self.νm+? + [Link] (these values
are passed as parameters to the End_simples constructor within the End_com class constructor, as there is a relationship between these two classes.
inheritance relationship). The Endereco method of End_com concatenates the string returned by the Endereco method of End_simples with the value
from the variable [Link] of End_com, this string concatenated is its return value.

8. Within the context of programming languages and object orientation, the concept of polymorphism
describe ways in which abstract and concrete classes can relate. Indicate the alternative that correctly defines polymorphism.

One possible way to implement polymorphism in a programming language is through parametric universal polymorphism.
in which type conversion of the parameters of a function occurs implicitly.
Programming languages that implement the concept of inheritance also need to implement the concept of polymorphism as
construction.
Programming languages that do not have types, such as Python, cannot implement polymorphism.

The implementation of polymorphism in programming languages relies on the concept of late binding, in which the type of a variable is only
It is known at runtime. This means that compiled languages do not have polymorphism in the strict sense.
Polymorphism represents a concept in which the same name (such as a variable, for example) can denote objects of different
classes that are related by a common superclass.

In the context of object-oriented programming, polymorphism is the ability for an object variable to assume, in certain situations,
different forms and behaviors.

10. Consider the script and respond.


Replacing the use of Threads with Processes on line 14, what value will be printed by line 18

Impossible to determine

10

1000000

100000
Data Resp.: 08/19/2022 10:10:47

Explanation:

The correct answer is: 0

No
Not Recorded Recorded
Responded

Exercise started on 08/19/2022 09:59:19.


Polymorphism represents a concept in which the same name (such as
a variable, for example, can denote objects of different classes
that are related by a common superclass.
In the context of object-oriented design, Polymorphism is the
ability to, in certain situations, an object variable
to assume different forms and behaviors.

In programming, an interpreter is a computer program capable of


analyze and execute other programs, which are generally more
slower than the compiled ones due to the need to translate
program while it is running.
An interpreted language is a programming language for
to which most of your implementations run the
instructions directly, without a previous compilation of the program
in machine language instructions.

The programming language Python is widely used in


relevance for different purposes precisely because it is a language of
generalist high-level programming. The practice of
Questions like these are interesting because they make us learn.
about libraries and functions. The Math library for example in
helps to deal more easily with mathematical functions.

What is a recursive function?


A function is considered recursive when, at some part of the
its own definition, calls itself.
We have the following function written in Python, following the
respective indentations:
___________________________________
deffoo(n):
foo is the name of the function.

ifn > 1:
The following code will be executed while n is greater than 1.
return foo(n-1)
At this moment we have a product of the value n by the result
of the function applied again, now, on (n - 1). This is where it happens
recursiveness.
return
when n is less than or equal to 1 the function will return n.
print(foo (4))
The result of the function applied to the number 4 will be printed on the screen.

_______________________________
Therefore, it can be observed that the program is executing the
next multiplication: 4 x 3 x 2 x 1 = 24

Python code
Python is a programming language launched in 1991, designed for
programming with several versions already released.

The question we answer deals with a version.


an outdated Python that is no longer supported, which can lead to
the one that responds to error. If we used, for example
In Python 3+, the answer would be different.

Data, information and knowledge


The data are low levels of abstraction of the real world, they do not
possuem sentido ou ordem, porém, podem ser ordenados e receber
a sense to form information.
A set of logically connected information can produce
knowledge, which is a skill that can be learned, is
a very high level of abstraction.
1a Correction:1.0/1.0
Question
In relation to systems programming, evaluate the following statements?

I - System programming lacks languages that directly access the


hardware and its components.
II - Examples of use: basic software, such as operating systems, translators and
programming language interpreters.

III - The main languages used are: Pascal, Java, and Ruby.

IV - Before high-level languages, system programming was developed


in Assembly.

Based on your analysis, mark the ONLY option that presents ONLY the assertions
correct
I, II and IV
I and IV
II, III and IV
III and IV
I
Answered on 08/19/2022 09:32:16

Explanation:

The correct answer is: I, II and IV

2a Correction:1.0/1.0
Questão
1.

Which of the languages below has no abstraction?


machine language
JAVA language
Assembly language
Python language
HTML language
Answered on 08/19/2022 09:32:42

Explanation:

The correct answer is: machine language.

3a
Right:1.0/1.0
Question
Consider the following fragment of source code written in the Python language:

def foo(a):
return a + a + a

b = 1

foo(b)

foo(b)

foo(b)

Após a execução de todos esses códigos, qual é o valor a ser mostrado mediante o
below command?

print(b)
6
0
1
9
3
Answered on 08/19/2022 09:33:30

Explanation:

The correct answer is: 1.

The function foo aims to return three times the value of a. When we apply the function foo
to the value we should have as a result the value 3. However, it is noticeable that the code does not at all
moment reveals on the user's screen the value of the function foo over variable b. For the value of
return should be 3, the code should be changed to print(foo(b)).

4a Correction:1.0/1.0
Question
Data structures are responsible for organizing and storing data in a way
efficient, creating ways for the user to handle them. Widely used structures
and well-known are stacks, lists, and queues. Regarding Algorithms and Data Structures
Given the statements below, mark the CORRECT option:
Python is a compiled language, which, after this process, generates a
executable file, of the binary type.
Variable declaration is something mandatory in Python.
In conditional or looping commands, the separation of code blocks
In Python, it is done using indentation.
Lists in Python are sets of values, which can only be of the same
type, accessed by a numerical index starting at 0 (zero).
Python is a procedural language that does not include object-oriented programming.
objects.
Answered on 08/19/2022 09:34:53

Explanation:
The correct answer is: In conditional or loop commands, the separation of blocks of
Code in Python is done using indentation.

Python is an interpreted language that supports object-oriented programming. In


In Python, it is not necessary to declare a variable before using it, and the indentation of the code is
fundamental among the blocks for its proper functioning

5a
Correct:1.0/1.0
Question
The snippet of Python code is a recursive function for calculating the factorial of a
any natural number. However, it has a programming error.

On which line is the error and how to fix it so that the function works correctly
your purpose?
the code should be "if (n == 1) and (n == 0):" on line 2.
the code should be "return Factorial(n) * n -1;" on line 5.
the code should be "if (n == 1):" on line 2.
the code should be "return Factorial(n - 1) * n;" on line 5.
the code should be 'return 0' on line 3.
Answered on 08/19/2022 09:35:36

Explanation:

The correct answer is: the code should be "return Fatorial(n - 1) * n;" on line 5.

6a
Correct:1.0/1.0
Question
Observe the print function of the code written in Python below:

What is the output printed by this function?


24
4
32
20
16
Answered on 08/19/2022 09:36:11

Explanation:

The correct answer is: 24

7a
Correct:0.0/1.0
Question
(DPE-RJ/2014) Consider the following excerpt from a program written in the language
Python.

class Car(object):
def TalkToMe(self):
I am a car

class Fusca (Car):


def TalkToAFusca(self):
I am a Beetle

x = Car()
y = Beetle()

[Link]()
[Link]()

In the first block, the FaleComigo method is defined for the Carro class, which
simplesmente produz a mensagem "Sou um carro" ao ser invocado. Para a classe
Fusca, defined in the second block, the method FaleComUmFusca was defined, which only
produz a mensagem "Sou um Fusca". No terceiro bloco, os objetos x e y tornam-se
instances of the Car and Beetle classes, respectively. In the fourth block, the method
FaleComigo is invoked for each of the two objects, x and y. When executed, this
the program produces two lines on its output screen:

I am a car
I am a car

The message produced in the command [Link] is due to the mechanism of

Polymorphism.
Inheritance.
Interface.
Abstraction.
Associação.
Responded on 08/19/2022 09:37:09
Explanation:

The correct answer is: inheritance.

The mechanism that provided the behavior is INHERITANCE. Note that the child class (beetle)
inherits from the mother class (car) its methods and attributes adding a degree of specialization.

8a
Correct:1.0/1.0
Question
Within the context of programming languages
In object-oriented programming, the concept of polymorphism describes ways in which classes
abstract and concrete can relate. Mark the option that defines
correctly polymorphism.
A possible way to implement polymorphism in a language of
programming is through universal parametric polymorphism, in which the
type conversion of the parameters of a function happens implicitly.
Programming languages that do not have a type, such as, for example, Python
they cannot implement polymorphism.
Programming languages that implement the concept of inheritance also
they need to implement the concept of polymorphism by construction.
The implementation of polymorphism in programming languages relies on
late binding concept, where the type of a variable is only known in
execution time. This means that compiled languages do not have
polymorphism in its strict form.
Polymorphism represents a concept in which the same name (such as a
variable, for example, can denote objects of different classes that are
related by a common superclass.
Replied on 08/19/2022 09:37:42

Explanation:

The correct answer is: Polymorphism represents a concept in which the same name (such as
a variable, for example, can denote objects of different classes that are related
for a common superclass.

In the context of object-oriented programming, Polymorphism is the ability to, in certain


situations, an object variable takes on different forms and behaviors.

9a Agreement:1.0/1.0
Question
Consider the following code snippet and answer:
What elements will be present in the variable my_filtered_list after execution?
of this program:
0 and 5
15, 20, 25 e 30
10, 15, 20, 25 e 30
0, 5, 10, 15, 20, 25 e 30
0, 5 and 10
Answered on 08/19/2022 09:39:48

Explanation:

The correct answers are: 15, 20, 25, and 30.

10a
Correct:1.0/1.0
Question
Consider the script and respond.
By replacing the use of Threads with Processes on line 14, what value will be printed?
through line 18
0
1,000,000
Impossible to determine
100000
10
Answered on 08/19/2022 09:40:33

Explanation:

The correct answer is: 0

You might also like