Docsity

Python Homework: Tuples, Lists, Sets and Machine Learning, Exams of Economics

Toggle sidebar
bg1
Homework 5
Exercise 1. Do the exercises from 5.2 to 5.7 in the textbook.
Exercise 2. a) Access value 20 from the following tuple: aTuple = ("Orange", [10, 20,
30], (5, 15, 25)). Expected output: 20
b) Remove an empty tuple(s) from a list of tuples.
Sample data: [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')] . Expected output: [('',), ('a', 'b'), ('a', 'b',
'c'), 'd']
c) Modify the first item (22) of a list inside a following tuple to 222
tuple1 = (11, [22, 33], 44, 55). Expected output: tuple1 = (11, [222, 33], 44, 55)
Exercise 3. a) Add a list of elements to a given set
sampleSet = {"Yellow", "Orange", "Black"}
sampleList = ["Blue", "Green", "Red"]
Expected output: In set item order is not a concern
{'Green', 'Yellow', 'Black', 'Orange', 'Red', 'Blue'}
b) Remove 10, 20, 30 elements from a following set at once
set1 = {10, 20, 30, 40, 50}
Expected output: {40, 50}
Exercise 4. ) Return a set of identical items from a given two Python set
set1 = {10, 20, 30, 40, 50}
set2 = {30, 40, 50, 60, 70}
Expected output:
a) {40, 50, 30}
b) {70, 40, 10, 50, 20, 60, 30}
c) {10,20}
d) {10,20,60,70}
Exercise 5. Let a message:
Machine learning; (ML) is the study of \ computer algorithms that improve automatically
through# experience. It is seen as a subset of artificial intelligence. Machine learning
algorithms build a mathematical model based on sample data, known as "training data", in
order to make predictions or decisions without being explicitly programmed to do so.
Machine{ learning} algorithms are used in a wide variety of applications, such as email
filtering and computer() vision, where it is difficult or infeasible to develop conventional
algorithms to perform the needed tasks. Machine# learning is closely related to
computational *statistics, which focuses on making predictions! using computers. The
study of mathematical optimization delivers methods, theory and application domains to
the-- field ;of machine learning. Data mining is a related field of study, focusing on
pf2

Partial preview of the text

Download Python Homework: Tuples, Lists, Sets and Machine Learning and more Exams Economics in PDF only on Docsity!

Homework 5

Exercise 1. Do the exercises from 5. 2 to 5. 7 in the textbook.

Exercise 2. a) Access value 20 from the following tuple: aTuple = ("Orange", [10, 20,

30], (5, 15, 25)). Expected output: 20 b) Remove an empty tuple(s) from a list of tuples. Sample data: [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]. Expected output: [('',), ('a', 'b'), ('a', 'b', 'c'), 'd'] c) Modify the first item (22) of a list inside a following tuple to 222 tuple1 = (11, [22, 33], 44, 55). Expected output: tuple1 = (11, [222, 33], 44, 55)

Exercise 3. a) Add a list of elements to a given set

sampleSet = {"Yellow", "Orange", "Black"} sampleList = ["Blue", "Green", "Red"] Expected output: In set item order is not a concern {'Green', 'Yellow', 'Black', 'Orange', 'Red', 'Blue'} b) Remove 10, 20, 30 elements from a following set at once set1 = {10, 20, 30, 40, 50} Expected output: {40, 50}

Exercise 4. ) Return a set of identical items from a given two Python set

set1 = {10, 20, 30, 40, 50} set2 = {30, 40, 50, 60, 70} Expected output: a) {40, 50, 30} b) {70, 40, 10, 50, 20, 60, 30} c) {10,20} d) {10,20,60,70}

Exercise 5. Let a message:

Machine learning; (ML) is the study of \ computer algorithms that improve automatically through# experience. It is seen as a subset of artificial intelligence. Machine learning algorithms build a mathematical model based on sample data, known as "training data", in order to make predictions or decisions without being explicitly programmed to do so. Machine{ learning} algorithms are used in a wide variety of applications, such as email filtering and computer() vision, where it is difficult or infeasible to develop conventional algorithms to perform the needed tasks. Machine# learning is closely related to computational *statistics, which focuses on making predictions! using computers. The study of mathematical optimization delivers methods, theory and application domains to the-- field ;of machine learning. Data mining is a related field of study, focusing on

exploratory data analysis through unsupervised learning In its application across business problems, machine learning is also referred to as predictive analytics. a) How many words are there in the message? b) How many different words are there in the message? c) Count the frequency of each word.

Exercise 6. Consider the following code

Each item on the list of customers contains the name, age, and the money that has to payed. a) Calculate the total amount the customer needs to pay (Same name and exact age are considered one customer). b) The following discount program is applied to celebrate National Day on September

Calculate the total amount to be paid for each customer (Gift = 2$).

Exercise 7. Write a python program to read and calculus the expression in the latex form:

“A(x,y)=2xy+4x+5y+x^2 - y^2- 5 ” a) How many variables? b) Enter the values of variables by the user and then calculus A(x,y) respective.