0% found this document useful (0 votes)
8 views22 pages

Rivera - Homework 1 - SP - U2

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)
8 views22 pages

Rivera - Homework 1 - SP - U2

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
You are on page 1/ 22

Rivera Medina Paola Sofía June 9th, 2024

Universidad Politécnica de Yucatán

Structural Programming

Puerto Adrián

Robotics 2ºC

Rivera Medina Paola Sofía

June 9th, 2024


June 9th, 2024

Homework1–U2

Universidad Politécnica de Yucatán

Subject: Structured Programming

Instructions: Review the reference 1and complete all is requested in each point.
For each of the exercises it is necessary to generate evidence taken directly from
your computer.

Deadline: 09/06/24.

1. Program the following exercises


a. 3-1

1
June 9th, 2024

b. 3-2

2
June 9th, 2024

c. 3-2

3
June 9th, 2024

d. 3-4

4
June 9th, 2024

e. 3-5

5
June 9th, 2024

2. Answer the following questions.

a. What is a control structure?

Is a logical design that controls the order in which a set of statements execute.

b. What is a decision structure?

Decision structures are also known as selection structures.) In a decision


structure’s simplest form, a specific action is performed only if a certain
condition exists. If the condition does not exist, the action is not performed.

c. What is a single alternative decision structure?

It provides only one alternative path of execution. If the condition in the


diamond symbol is true, we take the alternative path. Otherwise, we exit the
structure.

d. What is a Boolean expression?


The expressions that are tested by the if statement,

e. What types of relationships between values can you test with relational
operators?

f. Write an if statement that assigns 0 to x if y is equal to 20.

g. Write an if statement that assigns 0.2 to commissionRate if sales is


greater than or equal to 10000.

6
June 9th, 2024

h. What would the following code display?

if 'z' < 'a':


print('z is less than a.')

else:

print('z is not less than a.')

z is not less than a.

i. What would the following code display?

s1 = 'New York'
s2 = 'Boston'

if s1 > s2:
print(s2)
print(s1)

else:

print(s1)
print(s2)

Boston

New York

7
June 4th, 2024

Classroom Task

1. Program (in python) the programs 2-14 to 2-22 proposed in Reference

Program 2-14
June 4th, 2024

Program 2-15
June 4th, 2024

Program 2-16
June 4th, 2024

Program 2-17
June 4th, 2024

Program 2-18

Program 2-19
June 4th, 2024

Program 2-20

Program 2-21
June 4th, 2024

Program 2-22
June 4th, 2024

Program 2-23
June 4th, 2024

Classroom Task

2. Write the most important information from the following references:

• Python Variables

Python Variable is containers that store values. Python is not “statically


typed”. We do not need to declare variables before using them or declare their
type. A variable is created the moment we first assign a value to it. A Python
variable is a name given to a memory location. The value stored in a variable
can be changed during program execution. A Variables in Python is only a name
given to a memory location, all the operations done on the variable effects that
memory location. Example:

Rules for Python variables

A Python variable name must start with a letter or the underscore character.
A Python variable name cannot start with a number. A Python variable name can
only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).
Variable in Python names are case-sensitive (name, Name, and NAME are three
different variables). The reserved words(keywords) in Python cannot be used to
name the variable in Python.
Rules of global keyword

If a variable is assigned a value anywhere within the function’s body, it’s


assumed to be local unless explicitly declared as global. Variables that are only
referenced inside a function are implicitly global. We use a global in Python to
use a global variable inside a function. There is no need to use a global keyword
in Python outside a function.
June 4th, 2024

• Python Data Types

Python Data types are the classification or categorization of data items. It


represents the kind of value that tells what operations can be performed on a
particular data.

Numeric

Python provides three distinct numeric data types to handle various types of
numeric values:

Integers: Represented by the int class. Contains positive or negative


whole numbers without fractions or decimals. No limit on the length of an
integer value. Example: 42, -7, 1000000.

Float: Represented by the float class. Real numbers with floating-point


representation, specified by a decimal point. Scientific notation can be used,
with e or E followed by a positive or negative integer. Example: 3.14, -0.001,
1.5e3 (which is 1500).

Complex Numbers: Represented by the complex class. Composed of a


real part and an imaginary part, specified as (real part) + (imaginary part) j.
Example: 2+3j, -1+4.5j.

Sequence Type

Sequence data types are ordered collections of items, which can be of


similar or different types.
June 4th, 2024

String (str): Arrays of bytes representing Unicode characters. Created


using single, double, or triple quotes.

List (list): Ordered and mutable collection of items.

Tuple (tuple): Ordered and immutable collection of items.

Boolean

Boolean data type represents one of two built-in values: True or False.

Set

A set is an unordered collection of unique elements.

Dictionary

A dictionary is an unordered collection of key-value pairs.

Binary Types
They include memoryview, bytearray, bytes.
June 4th, 2024

• Libraries in Python

How Do Python Libraries Work?

Python libraries consist of codes or modules that can be integrated into a program
for specific operations. In a Windows environment, these libraries often have a DLL
extension (Dynamic Load Libraries). When a program runs, the linker searches for
the linked library, extracts its functionalities, and incorporates them into the program.

Commonly Used Python Libraries

TensorFlow: Developed by Google, TensorFlow is an open-source library for


high-level computations, machine learning, and deep learning algorithms. It is
widely used for complex mathematical and physical computations.
Matplotlib: An open-source library for plotting numerical data, Matplotlib is
essential in data analysis, providing high-quality visualizations such as pie
charts, histograms, scatterplots, and graphs.

Pandas: Crucial for data scientists, Pandas is an open-source library that offers
flexible data structures and analysis tools. It simplifies data analysis,
manipulation, and cleaning with support for operations like sorting, re-indexing,
iteration, concatenation, and aggregation.

Numpy: Known as “Numerical Python,” Numpy is a popular library for handling


large matrices and multi-dimensional data. It includes built-in mathematical
functions and is integral to other libraries like TensorFlow.
SciPy: Standing for “Scientific Python,” SciPy is built on Numpy and used for high-
level scientific computations. It handles complex numerical data storage and is
widely used by application developers and engineers.

Scrapy: An open-source library for web crawling and data extraction, Scrapy
excels in data mining and automated testing.

Scikit-learn: A renowned machine learning library, Scikit-learn supports various


supervised and unsupervised algorithms and works closely with Numpy and
SciPy.

PyGame: This library provides an interface for developing video games using the
SDL (Standard Directmedia Library) platform-independent graphics, audio, and
input libraries.

PyTorch: A leading machine learning library, PyTorch optimizes tensor


computations and supports GPU acceleration. It is extensively used in neural
network applications.
June 4th, 2024

PyBrain: PyBrain, or Python Based Reinforcement Learning, Artificial Intelligence,


and Neural Networks library, is designed for beginners in machine learning. It
offers easy-to-use algorithms and flexible, understandable interfaces.

Using Libraries in Python Programs

To maintain modularity in large programs, Python uses modules, which can be


imported as needed. This avoids code duplication and simplifies program
maintenance. Multiple interrelated modules are stored in libraries, which can be
imported easily using the import statement.

• How to Install PIP in Python | PIP Install in Python (2024)

On cmd, we check our Python version, and if the program recognizes “pip”. To install
it, we write curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py.

Once we got this, we need to write python get-pip.p


June 4th, 2024

Later, we need to create the path on C:\Python\Scripts. Once created, we need to


verify the version of pip installed.

On Code Visual Studio we write on the terminal “pip install numpy”.

And that´s all.

You might also like