程序案例-SCC461

SCC461 – Programming for Data Scientists
Leandro Marcolino
Lancaster University
Week 6 – Discussions
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 1 / 34
Module Structure
Outline
1 Module Structure
2 Exercises
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 1 / 34
Module Structure
Overview
Weeks 1 to 5:
Taught by Clement
Focused on the statistical side of programming using R
Weeks 6 to 10
Taught by Leandro
Object-oriented programming using Python
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 2 / 34
Module Structure
Tentative Schedule
Week 6: Basics of programming
Week 7: OOP + Data Structures I
Week 8: Data Structures II
Week 9: Inheritance + Libraries
Week 10: Problem Solving
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 3 / 34
Module Structure
Assessment
Weekly Assessment (25%)
Deadline: 9am the following Monday
Moodle Quiz
Plenty of comments
Immediate Feedback
Multiple attempts per question allowed, but with a penalty
Pre-check available, no penalty
Assignment (50%)
Details will be published in week 8, due in week 11 (after Christmas)
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 4 / 34
Module Structure
Teaching Assistants
Gao Peng, [email protected]
Somayeh Bazin, [email protected]
Abdulrahman Kerim, [email protected]
Farid Bello, [email protected]
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 5 / 34
Exercises
Outline
1 Module Structure
2 Exercises
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 5 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 8]
for x in myList:
print(x)
Iterative code
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 6 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 8]
for x in myList:
print(x)
Iterative code
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 6 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 8]
for x in range(len(myList)):
print(x)
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 7 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 8]
for x in range(len(myList)):
print(myList[x])
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 8 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 8]
for x in myList:
x = 5
print(myList [0])
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 9 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 99, 95, 7]
x = -1
xPos = -1
for y in range(len(myList)):
if (myList[y] > x):
x = myList[y]
xPos = y
print(x)
print(xPos)
Leandro Marcolino (Lancaster) SCC461 Week 6 �

💡 Buy the answer for only $12 Get it now →

�� Discussions 10 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 99, 95, 7]
x = -1
xPos = -1
for y in range(len(myList)):
if (y == 2):
continue
if (myList[y] > x):
x = myList[y]
xPos = y
print(x)
print(xPos)
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 11 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 99, 95, 7]
x = -1
xPos = -1
for y in range(len(myList)):
if (y == 2):
break
if (myList[y] > x):
x = myList[y]
xPos = y
print(x)
print(xPos)
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 12 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 10, 23, 2, 3]
specialList = []
for x in myList:
if (x % 2 == 0):
specialList.append(x)
print(specialList [1])
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 13 / 34
Exercises
Lists
What will be printed
myList = [3, 4, 7, 10, 23, 2, 3]
specialList = []
for x in myList:
if (x % 2 != 0):
specialList.append(x)
print(specialList [1])
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 14 / 34
Exercises
Exercises
Exercise handout, “1. Fundamentals”
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 15 / 34
Exercises
Functions
What will be printed
def callMe(y):
b = 5;
return y*b;
x = callMe (5);
print(x);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 16 / 34
Exercises
Functions
What will be printed
def callMe(y):
b = 5;
x = 10;
return y*b;
b = 3;
x = callMe (5);
print(x);
print(b);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 17 / 34
Exercises
Exercises
Exercise handout, “2. Functions”
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 18 / 34
Exercises
Pointers
What will be printed
a = 2;
b = a;
b = 999;
print(a);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 19 / 34
Exercises
Pointers
What will be printed
a = [1, 2, 3, 4, 5];
b = a;
b[1] = 999;
print(a);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 20 / 34
Exercises
Pointers
What will be printed
a = [1, 2, 3, 4, 5];
b = a[:];
b[1] = 999;
print(a);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 21 / 34
Exercises
Pointers
What will be printed
def callMe(x):
x = 1;
return;
myInput = 0;
callMe(myInput);
print(myInput);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 22 / 34
Exercises
Pointers
What will be printed
def callMe(x):
x[0] = 1;
return;
myList = [0];
callMe(myList);
print(myList [0]);
Leandro Marcolino (Lancaster) SCC461 Week 6 – Discussions 23 / 34
Exercises
Recursive Functions
How do you sum n numbers
5 + 8 + 18 + 5 + 2 + 20 …
First number + sum n 1 numbers
Wha
t is
the
Pyth
on c
ode

💡 Buy the answer for only $12 Get it now →