csci 127: introduction to computer science · 2020. 1. 16. · low-level vs. high-level languages...

57
CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 1 / 36

Upload: others

Post on 10-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 1 / 36

Page 2: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Lecture Slips: tinyurl.com/ycrcn3k6

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 2 / 36

Page 3: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Announcements

There’s 7 additional sections for the secondsemester programming lab CSci 136 open fornext term.

Today’s lecturers include:

I Prof. Sakas (department chair),I Genady Maryash (adjunct coordinator),I Katherine Howitt (tutor coordinator).

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 3 / 36

Page 4: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Announcements

There’s 7 additional sections for the secondsemester programming lab CSci 136 open fornext term.

Today’s lecturers include:

I Prof. Sakas (department chair),I Genady Maryash (adjunct coordinator),I Katherine Howitt (tutor coordinator).

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 3 / 36

Page 5: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Today’s Topics

Recap of Low-Level Programming

Introducing C++

Hello, World in C++

I/O and Definite Loops in C++

Final Exam Overview

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 4 / 36

Page 6: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.

Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 5 / 36

Page 7: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.Those that directly access machine instructions & memory and havelittle abstraction are low-level languages

(e.g. machine language, assembly language).Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 5 / 36

Page 8: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).

Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 5 / 36

Page 9: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.

Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 5 / 36

Page 10: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 5 / 36

Page 11: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 6 / 36

Page 12: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 6 / 36

Page 13: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 6 / 36

Page 14: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 6 / 36

Page 15: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

“Hello World!” in Simplified Machine Language

(WeMIPS)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 7 / 36

Page 16: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

In Pairs or Triples:

Predict what the code will do:

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 8 / 36

Page 17: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

WeMIPS

(Demo with WeMIPS)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 9 / 36

Page 18: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

In Pairs or Triples:

Write a complete Python program that converts kilograms topounds.

Predict what the code will do:

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 10 / 36

Page 19: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Python TutorWrite a complete Python program that converts kilograms topounds.

(Write from scratch in pythonTutor.)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 11 / 36

Page 20: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

onlinegdb demo

(Demo with onlinegdb)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 12 / 36

Page 21: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

C++ is a popular programminglanguage that extends C.

Produces fast, efficient, and powerful.

Used for systems programming (andfuture courses!).

Today, we’ll introduce the basicstructure and simple input/output(I/O) in C/C++.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 13 / 36

Page 22: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

C++ is a popular programminglanguage that extends C.

Produces fast, efficient, and powerful.

Used for systems programming (andfuture courses!).

Today, we’ll introduce the basicstructure and simple input/output(I/O) in C/C++.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 13 / 36

Page 23: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

C++ is a popular programminglanguage that extends C.

Produces fast, efficient, and powerful.

Used for systems programming (andfuture courses!).

Today, we’ll introduce the basicstructure and simple input/output(I/O) in C/C++.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 13 / 36

Page 24: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

C++ is a popular programminglanguage that extends C.

Produces fast, efficient, and powerful.

Used for systems programming (andfuture courses!).

Today, we’ll introduce the basicstructure and simple input/output(I/O) in C/C++.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 13 / 36

Page 25: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 26: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:

int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 27: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 28: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 29: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:

cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 30: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 31: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:

cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 32: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 33: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:

#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 34: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Introduction to C++

Programs are organized in functions.

Variables must be declared beforeused:int num;

Many types available: int, float,

char, ...

To print, we’ll use cout <<:cout << "Hello!!"

To get input, we’ll use cin >>:cin >> num

To use those I/O functions, we put atthe top of the program:#include <iostream>using namespace std;

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 14 / 36

Page 35: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

In Pairs or Triples:Predict what the following pieces of code will do:

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 15 / 36

Page 36: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

C++ Demo

(Demo with onlinegdb)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 16 / 36

Page 37: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

In Pairs or Triples:

Predict what the following pieces of code will do:

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 17 / 36

Page 38: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

C++ Demo

(Demo with C++)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 18 / 36

Page 39: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Definite loops

General format:

for ( initialization ; test ; updateAction ){

command1;command2;command3;...

}

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 19 / 36

Page 40: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final Overview (Cont’d from Last Lecture)For each question below, first write the function header (name &inputs) and return values (often called the Application ProgrammingInterface (API)). Then write the complete function:

Write a function that takes a whole number and returns thecorresponding binary number as a string.

Write a function that takes a weight in kilograms and returns theweight in pounds.

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

Write a function that takes a string and returns its length.

(Hint: highlight key words, make list of inputs, list of outputs, then puttogether.)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 20 / 36

Page 41: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a whole number and returns thecorresponding binary number as a string.

def num2bin(num):

...

return(bin)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 21 / 36

Page 42: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a whole number and returns thecorresponding binary number as a string.

def num2bin(num):

binStr = ""

while (num > 0):

#Divide by 2, and add the remainder to the string

r = num %2

binString = str(r) + binStr

num = num / 2

return(binStr)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 22 / 36

Page 43: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 23 / 36

Page 44: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

def kg2lbs(kg):

...

return(lbs)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 24 / 36

Page 45: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

def kg2lbs(kg)

lbs = kg * 2.2

return(lbs)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 25 / 36

Page 46: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 26 / 36

Page 47: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

def getMin(df):

...

return(min)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 27 / 36

Page 48: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

def getMin(df):

mM = df[’Manhattan’].min()

return(mM)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 28 / 36

Page 49: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 29 / 36

Page 50: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

def computePayment(loan,rate,year):

....

return(payment)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 30 / 36

Page 51: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

def computePayment(loan,rate,year):

(Some formula for payment)

return(payment)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 31 / 36

Page 52: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a string and returns its length.

def sLength(str):

...

return(length)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 32 / 36

Page 53: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a string and returns its length.

def sLength(str):

length = len(str)

return(length)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 33 / 36

Page 54: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Recap: C++

C++ is a popular programming languagethat extends C.

Input/Output (I/O):

I cin >>I cout <<

Definite loops:for (i = 0; i < 10; i++)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 34 / 36

Page 55: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Recap: C++

C++ is a popular programming languagethat extends C.

Input/Output (I/O):

I cin >>I cout <<

Definite loops:for (i = 0; i < 10; i++)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 34 / 36

Page 56: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Recap: C++

C++ is a popular programming languagethat extends C.

Input/Output (I/O):

I cin >>I cout <<

Definite loops:for (i = 0; i < 10; i++)

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 34 / 36

Page 57: CSci 127: Introduction to Computer Science · 2020. 1. 16. · Low-Level vs. High-Level Languages (codeCommit) Can view programming languages on a continuum. Those that directly access

Lecture Slips: tinyurl.com/ycrcn3k6

CSci 127 (Hunter) Lecture 12: tinyurl.com/ycrcn3k6 22 November 2017 35 / 36