+ All Categories
Home > Documents > CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40....

CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40....

Date post: 29-Jul-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
120
CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40
Transcript
Page 1: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40

Page 2: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 3: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?

No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 4: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must:

Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 5: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges;

Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 6: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture);

Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 7: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!);

Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 8: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 9: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?

Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 10: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 11: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?

There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 12: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 13: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?

No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 14: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 15: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.

That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 16: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 17: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Frequently Asked QuestionsFrom previous semesters

Am I only responsible for reading the weekly Lab?No. Each class you must: Attend lecture; Participate in challenges; Take a Quiz(on Gradescope, immediately after lecture); Read the weekly lab (online, seeCourse Outline on course website, find it on Blackboard!!!); Submit programmingassignments to Gradescope (approx. 6 per lab)

Can I work ahead?Absolutely! Submission is open on Gradescope, 2 weeks before the deadline. Startright away (after Lab 1 you can submit the first 5 problems)

When is the midterm?There is no midterm. Instead there’s required quizzes each class and 60programming assignments.

I missed class. Do you need documentation?No, but If you will miss ≥ 2 class meetings (> 20%), see us about taking this in afuture term. The summer semester moves VERY quickly. Missing any class is notideal.

I have not received any emails from this course.That is a big problem! We send tons of important information through email.Please update your email on Blackboard to one you check regularly.

CSci 127 (Hunter) Lecture 2 Summer 2020 2 / 40

Page 18: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Today’s Topics

For-loops

range()

Variables

Characters

Strings

CS Survey (Dr. Sakas, ComputationalLinguistics)

CSci 127 (Hunter) Lecture 2 Summer 2020 3 / 40

Page 19: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Challenge Problem...

Some review and some novel challenges:

CSci 127 (Hunter) Lecture 2 Summer 2020 4 / 40

Page 20: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 2 Summer 2020 5 / 40

Page 21: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

for-loop

How to Think Like CS, §4.5

for i in list:

statement1

statement2

statement3

where list is a list of items:

stated explicitly (e.g. [1,2,3]) or

generated by a function,e.g. range().

CSci 127 (Hunter) Lecture 2 Summer 2020 6 / 40

Page 22: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

for-loop

How to Think Like CS, §4.5

for i in list:

statement1

statement2

statement3

where list is a list of items:

stated explicitly (e.g. [1,2,3]) or

generated by a function,e.g. range().

CSci 127 (Hunter) Lecture 2 Summer 2020 6 / 40

Page 23: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Today’s Topics

For-loops

range()

Variables

Characters

Strings

CS Survey (Dr. Sakas, ComputationalLinguistics)

CSci 127 (Hunter) Lecture 2 Summer 2020 7 / 40

Page 24: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on range():

CSci 127 (Hunter) Lecture 2 Summer 2020 8 / 40

Page 25: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 2 Summer 2020 9 / 40

Page 26: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

Simplest version:

range(stop)

Produces a list: [0,1,2,3,...,stop-1]

For example, if you want the the list[0,1,2,3,...,100], you would write:

range(101)

CSci 127 (Hunter) Lecture 2 Summer 2020 10 / 40

Page 27: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

Simplest version:

range(stop)

Produces a list: [0,1,2,3,...,stop-1]

For example, if you want the the list[0,1,2,3,...,100], you would write:

range(101)

CSci 127 (Hunter) Lecture 2 Summer 2020 10 / 40

Page 28: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

Simplest version:

range(stop)

Produces a list: [0,1,2,3,...,stop-1]

For example, if you want the the list[0,1,2,3,...,100], you would write:

range(101)

CSci 127 (Hunter) Lecture 2 Summer 2020 10 / 40

Page 29: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

Simplest version:

range(stop)

Produces a list: [0,1,2,3,...,stop-1]

For example, if you want the the list[0,1,2,3,...,100], you would write:

range(101)

CSci 127 (Hunter) Lecture 2 Summer 2020 10 / 40

Page 30: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to start somewhere else:

range(start, stop)

Produces a list:[start,start+1,...,stop-1]

For example, if you want the the list[10,11,...,20]you would write:

range(10,21)

CSci 127 (Hunter) Lecture 2 Summer 2020 11 / 40

Page 31: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to start somewhere else:

range(start, stop)

Produces a list:[start,start+1,...,stop-1]

For example, if you want the the list[10,11,...,20]you would write:

range(10,21)

CSci 127 (Hunter) Lecture 2 Summer 2020 11 / 40

Page 32: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to start somewhere else:

range(start, stop)

Produces a list:[start,start+1,...,stop-1]

For example, if you want the the list[10,11,...,20]you would write:

range(10,21)

CSci 127 (Hunter) Lecture 2 Summer 2020 11 / 40

Page 33: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to start somewhere else:

range(start, stop)

Produces a list:[start,start+1,...,stop-1]

For example, if you want the the list[10,11,...,20]you would write:

range(10,21)

CSci 127 (Hunter) Lecture 2 Summer 2020 11 / 40

Page 34: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to start somewhere else:

range(start, stop)

Produces a list:[start,start+1,...,stop-1]

For example, if you want the the list[10,11,...,20]you would write:

range(10,21)

CSci 127 (Hunter) Lecture 2 Summer 2020 11 / 40

Page 35: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to count by twos, orsome other number:

range(start, stop, step)

Produces a list:[start,start+step,start+2*step...,last](where last is the largest start+k*stepless than stop)

For example, if you want the the list[5,10,...,50]you would write:

range(5,51,5)

CSci 127 (Hunter) Lecture 2 Summer 2020 12 / 40

Page 36: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to count by twos, orsome other number:

range(start, stop, step)

Produces a list:[start,start+step,start+2*step...,last](where last is the largest start+k*stepless than stop)

For example, if you want the the list[5,10,...,50]you would write:

range(5,51,5)

CSci 127 (Hunter) Lecture 2 Summer 2020 12 / 40

Page 37: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to count by twos, orsome other number:

range(start, stop, step)

Produces a list:[start,start+step,start+2*step...,last](where last is the largest start+k*stepless than stop)

For example, if you want the the list[5,10,...,50]you would write:

range(5,51,5)

CSci 127 (Hunter) Lecture 2 Summer 2020 12 / 40

Page 38: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to count by twos, orsome other number:

range(start, stop, step)

Produces a list:[start,start+step,start+2*step...,last](where last is the largest start+k*stepless than stop)

For example, if you want the the list[5,10,...,50]you would write:

range(5,51,5)

CSci 127 (Hunter) Lecture 2 Summer 2020 12 / 40

Page 39: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

range()

What if you wanted to count by twos, orsome other number:

range(start, stop, step)

Produces a list:[start,start+step,start+2*step...,last](where last is the largest start+k*stepless than stop)

For example, if you want the the list[5,10,...,50]you would write:

range(5,51,5)

CSci 127 (Hunter) Lecture 2 Summer 2020 12 / 40

Page 40: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

In summary: range()

The three versions:

range(stop)

range(start, stop)

range(start, stop, step)

CSci 127 (Hunter) Lecture 2 Summer 2020 13 / 40

Page 41: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

In summary: range()

The three versions:

range(stop)

range(start, stop)

range(start, stop, step)

CSci 127 (Hunter) Lecture 2 Summer 2020 13 / 40

Page 42: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

In summary: range()

The three versions:

range(stop)

range(start, stop)

range(start, stop, step)

CSci 127 (Hunter) Lecture 2 Summer 2020 13 / 40

Page 43: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

In summary: range()

The three versions:

range(stop)

range(start, stop)

range(start, stop, step)

CSci 127 (Hunter) Lecture 2 Summer 2020 13 / 40

Page 44: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Today’s Topics

For-loops

range()

Variables

Characters

Strings

CS Survey (Dr. Sakas, ComputationalLinguistics)

CSci 127 (Hunter) Lecture 2 Summer 2020 14 / 40

Page 45: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 46: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbers

I float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 47: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbersI float: floating point or real numbers

I string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 48: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of characters

I list: a sequence of itemse.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 49: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 50: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 51: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variables

A variable is a reserved memorylocation for storing a value.

Different kinds, or types, of valuesneed different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or[’violet’,’purple’,’indigo’]

I class variables: for complex objects,like turtles.

In Python (unlike other languages)you don’t need to specify the type; itis deduced by its value.

CSci 127 (Hunter) Lecture 2 Summer 2020 15 / 40

Page 52: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variable Names

There’s some rules about valid names forvariables.

Can use the underscore (’ ’), upper andlower case letters.

Can also use numbers, just can’t start aname with a number.

Can’t use symbols (like ’+’ or ’*’) sinceused for arithmetic.

Can’t use some words that Python hasreserved for itself (e.g. for).(List of reserved words in Think CS, §2.5.)

CSci 127 (Hunter) Lecture 2 Summer 2020 16 / 40

Page 53: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variable Names

There’s some rules about valid names forvariables.

Can use the underscore (’ ’), upper andlower case letters.

Can also use numbers, just can’t start aname with a number.

Can’t use symbols (like ’+’ or ’*’) sinceused for arithmetic.

Can’t use some words that Python hasreserved for itself (e.g. for).(List of reserved words in Think CS, §2.5.)

CSci 127 (Hunter) Lecture 2 Summer 2020 16 / 40

Page 54: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variable Names

There’s some rules about valid names forvariables.

Can use the underscore (’ ’), upper andlower case letters.

Can also use numbers, just can’t start aname with a number.

Can’t use symbols (like ’+’ or ’*’) sinceused for arithmetic.

Can’t use some words that Python hasreserved for itself (e.g. for).(List of reserved words in Think CS, §2.5.)

CSci 127 (Hunter) Lecture 2 Summer 2020 16 / 40

Page 55: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variable Names

There’s some rules about valid names forvariables.

Can use the underscore (’ ’), upper andlower case letters.

Can also use numbers, just can’t start aname with a number.

Can’t use symbols (like ’+’ or ’*’) sinceused for arithmetic.

Can’t use some words that Python hasreserved for itself (e.g. for).(List of reserved words in Think CS, §2.5.)

CSci 127 (Hunter) Lecture 2 Summer 2020 16 / 40

Page 56: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Variable Names

There’s some rules about valid names forvariables.

Can use the underscore (’ ’), upper andlower case letters.

Can also use numbers, just can’t start aname with a number.

Can’t use symbols (like ’+’ or ’*’) sinceused for arithmetic.

Can’t use some words that Python hasreserved for itself (e.g. for).(List of reserved words in Think CS, §2.5.)

CSci 127 (Hunter) Lecture 2 Summer 2020 16 / 40

Page 57: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Today’s Topics

For-loops

range()

Variables

Characters

Strings

CS Survey (Dr. Sakas, ComputationalLinguistics)

CSci 127 (Hunter) Lecture 2 Summer 2020 17 / 40

Page 58: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Standardized Code for CharactersAmerican Standard Code for Information Interchange (ASCII), 1960.

(New version called: Unicode).

(wiki)

CSci 127 (Hunter) Lecture 2 Summer 2020 18 / 40

Page 59: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Standardized Code for CharactersAmerican Standard Code for Information Interchange (ASCII), 1960.

(New version called: Unicode).

(wiki)

CSci 127 (Hunter) Lecture 2 Summer 2020 18 / 40

Page 60: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Standardized Code for CharactersAmerican Standard Code for Information Interchange (ASCII), 1960.

(New version called: Unicode).

(wiki)

CSci 127 (Hunter) Lecture 2 Summer 2020 18 / 40

Page 61: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Converting from Character to Code:

(There is an ASCII table on the back of today’s

lecture slip.)

ord(c): returns Unicode (ASCII) of thecharacter.

Example: ord(’a’) returns 97.

chr(x): returns the character whoseUnicode is x.

Example: chr(97) returns ’a’.

What is chr(33)?

CSci 127 (Hunter) Lecture 2 Summer 2020 19 / 40

Page 62: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Converting from Character to Code:

(There is an ASCII table on the back of today’s

lecture slip.)

ord(c): returns Unicode (ASCII) of thecharacter.

Example: ord(’a’) returns 97.

chr(x): returns the character whoseUnicode is x.

Example: chr(97) returns ’a’.

What is chr(33)?

CSci 127 (Hunter) Lecture 2 Summer 2020 19 / 40

Page 63: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Converting from Character to Code:

(There is an ASCII table on the back of today’s

lecture slip.)

ord(c): returns Unicode (ASCII) of thecharacter.

Example: ord(’a’) returns 97.

chr(x): returns the character whoseUnicode is x.

Example: chr(97) returns ’a’.

What is chr(33)?

CSci 127 (Hunter) Lecture 2 Summer 2020 19 / 40

Page 64: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Converting from Character to Code:

(There is an ASCII table on the back of today’s

lecture slip.)

ord(c): returns Unicode (ASCII) of thecharacter.

Example: ord(’a’) returns 97.

chr(x): returns the character whoseUnicode is x.

Example: chr(97) returns ’a’.

What is chr(33)?

CSci 127 (Hunter) Lecture 2 Summer 2020 19 / 40

Page 65: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Converting from Character to Code:

(There is an ASCII table on the back of today’s

lecture slip.)

ord(c): returns Unicode (ASCII) of thecharacter.

Example: ord(’a’) returns 97.

chr(x): returns the character whoseUnicode is x.

Example: chr(97) returns ’a’.

What is chr(33)?

CSci 127 (Hunter) Lecture 2 Summer 2020 19 / 40

Page 66: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Converting from Character to Code:

(There is an ASCII table on the back of today’s

lecture slip.)

ord(c): returns Unicode (ASCII) of thecharacter.

Example: ord(’a’) returns 97.

chr(x): returns the character whoseUnicode is x.

Example: chr(97) returns ’a’.

What is chr(33)?

CSci 127 (Hunter) Lecture 2 Summer 2020 19 / 40

Page 67: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Challenge Problem...Some review and some novel challenges:

CSci 127 (Hunter) Lecture 2 Summer 2020 20 / 40

Page 68: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 2 Summer 2020 21 / 40

Page 69: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

User Input

Covered in detail in Lab 2:

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 2 Summer 2020 22 / 40

Page 70: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Side Note: ’+’ for numbers and strings

x = 3 + 5 stores the number 8 inmemory location x.

x = x + 1 increases x by 1.

s = "hi" + "Mom" stores "hiMom" inmemory locations s.

s = s + "A" adds the letter "A" to theend of the strings s.

CSci 127 (Hunter) Lecture 2 Summer 2020 23 / 40

Page 71: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Side Note: ’+’ for numbers and strings

x = 3 + 5 stores the number 8 inmemory location x.

x = x + 1 increases x by 1.

s = "hi" + "Mom" stores "hiMom" inmemory locations s.

s = s + "A" adds the letter "A" to theend of the strings s.

CSci 127 (Hunter) Lecture 2 Summer 2020 23 / 40

Page 72: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Side Note: ’+’ for numbers and strings

x = 3 + 5 stores the number 8 inmemory location x.

x = x + 1 increases x by 1.

s = "hi" + "Mom" stores "hiMom" inmemory locations s.

s = s + "A" adds the letter "A" to theend of the strings s.

CSci 127 (Hunter) Lecture 2 Summer 2020 23 / 40

Page 73: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Side Note: ’+’ for numbers and strings

x = 3 + 5 stores the number 8 inmemory location x.

x = x + 1 increases x by 1.

s = "hi" + "Mom" stores "hiMom" inmemory locations s.

s = s + "A" adds the letter "A" to theend of the strings s.

CSci 127 (Hunter) Lecture 2 Summer 2020 23 / 40

Page 74: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Today’s Topics

For-loops

range()

Variables

Characters

Strings

CS Survey (Dr. Sakas, ComputationalLinguistics)

CSci 127 (Hunter) Lecture 2 Summer 2020 24 / 40

Page 75: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.I num = s.count("s") stores the result in the variable num, for later.I What would print(s.count("sS")) output?I What about:

mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 76: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.I num = s.count("s") stores the result in the variable num, for later.I What would print(s.count("sS")) output?I What about:

mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 77: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.I num = s.count("s") stores the result in the variable num, for later.I What would print(s.count("sS")) output?I What about:

mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 78: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.

I num = s.count("s") stores the result in the variable num, for later.I What would print(s.count("sS")) output?I What about:

mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 79: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.I num = s.count("s") stores the result in the variable num, for later.

I What would print(s.count("sS")) output?I What about:

mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 80: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.I num = s.count("s") stores the result in the variable num, for later.I What would print(s.count("sS")) output?

I What about:mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 81: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: String Methods

s = "FridaysSaturdaysSundays"num = s.count("s")

The first line creates a variable, called s, that stores the string:"FridaysSaturdaysSundays"

There are many useful functions for strings (more in Lab 2).

s.count(x) will count the number of times the pattern, x,appears in s.

I s.count("s") counts the number of lower case s that occurs.I num = s.count("s") stores the result in the variable num, for later.I What would print(s.count("sS")) output?I What about:

mess = "10 20 21 9 101 35"

mults = mess.count("0 ")

print(mults)

CSci 127 (Hunter) Lecture 2 Summer 2020 25 / 40

Page 82: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

CSci 127 (Hunter) Lecture 2 Summer 2020 26 / 40

Page 83: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

CSci 127 (Hunter) Lecture 2 Summer 2020 26 / 40

Page 84: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

CSci 127 (Hunter) Lecture 2 Summer 2020 26 / 40

Page 85: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

CSci 127 (Hunter) Lecture 2 Summer 2020 26 / 40

Page 86: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[0] is

’F’.

CSci 127 (Hunter) Lecture 2 Summer 2020 27 / 40

Page 87: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[0] is ’F’.

CSci 127 (Hunter) Lecture 2 Summer 2020 27 / 40

Page 88: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[1] is

’r’.

CSci 127 (Hunter) Lecture 2 Summer 2020 28 / 40

Page 89: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[1] is ’r’.

CSci 127 (Hunter) Lecture 2 Summer 2020 28 / 40

Page 90: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[-1] is

’s’.

CSci 127 (Hunter) Lecture 2 Summer 2020 29 / 40

Page 91: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[-1] is ’s’.

CSci 127 (Hunter) Lecture 2 Summer 2020 29 / 40

Page 92: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[3:6] is

’day’.

CSci 127 (Hunter) Lecture 2 Summer 2020 30 / 40

Page 93: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[3:6] is ’day’.

CSci 127 (Hunter) Lecture 2 Summer 2020 30 / 40

Page 94: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[:3] is

’Fri’.

CSci 127 (Hunter) Lecture 2 Summer 2020 31 / 40

Page 95: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[:3] is ’Fri’.

CSci 127 (Hunter) Lecture 2 Summer 2020 31 / 40

Page 96: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[:-1] is

’FridaysSaturdaysSunday’.(no trailing ’s’ at the end)

CSci 127 (Hunter) Lecture 2 Summer 2020 32 / 40

Page 97: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Indexing & Substrings

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

Strings are made up of individual characters (letters, numbers, etc.)

Useful to be able to refer to pieces of a string, either an individuallocation or a “substring” of the string.

0 1 2 3 4 5 6 7 8 ... 16 17 18 19 20 21 22

F r i d a y s S a ... S u n d a y s

... -4 -3 -2 -1

s[:-1] is ’FridaysSaturdaysSunday’.(no trailing ’s’ at the end)

CSci 127 (Hunter) Lecture 2 Summer 2020 32 / 40

Page 98: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 99: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 100: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"

days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 101: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 102: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 103: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 104: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"

days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 105: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

More on Strings: Splits

s = "FridaysSaturdaysSundays"days = s[:-1].split("s")

split() divides a string into a list.

Cross out the delimiter, and the remaining items are the list.

"FridaysXSaturdaysXSunday"days = [’Friday’, ’Saturday’, ’Sunday’]

Different delimiters give different lists:

days = s[:-1].split("day")

"FridXaXyXsSaturdXaXyXsSundXaXyX"days = [’Fri’, ’sSatur’, ’sSun’]

CSci 127 (Hunter) Lecture 2 Summer 2020 33 / 40

Page 106: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Today’s Topics

For-loops

range()

Variables

Characters

Strings

CS Survey (Dr. Sakas, ComputationalLinguistics)

CSci 127 (Hunter) Lecture 2 Summer 2020 34 / 40

Page 107: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

CS Survey: Prof. Sakas, Computational ComputationalLinguistics

1

Language is Hard for Computers

Learning Language is Easy for my 3-year-old twins

CSCI 12700 Guest Bullet Talk

William Gregory Sakas

CSci 127 (Hunter) Lecture 2 Summer 2020 35 / 40

Page 108: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

CS Survey: Prof. Sakas, Computational ComputationalLinguistics

2

Language is Hard

•  Buffalo buffalo, Buffalo buffalo buffalo, buffalo, Buffalo buffalo

•  Someone shot the servant of the actress who was on the balcony. Who was on the balcony?

•  Who do you think Mary kissed? •  Who do you think that Mary kissed? •  Who do you think bought a radio? •  * Who do you think that bought a radio?

CSci 127 (Hunter) Lecture 2 Summer 2020 36 / 40

Page 109: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

CS Survey: Prof. Sakas, Computational ComputationalLinguistics

So how to explain language? Treat Language as a scientific field - like Physics.

Example: A scientific principle about sentences:

Given <p> = [α [Η β] ], where α = edge(Spec's) β then:

the head Η of <p> is inert after the phase is completed, triggering no further grammatical

operations.

Language is complex!!! Understanding how language works is hard!!!

Unless you're 3.

CSci 127 (Hunter) Lecture 2 Summer 2020 37 / 40

Page 110: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

CS Survey: Prof. Sakas, Computational ComputationalLinguistics

4

Linguistic experts! CSci 127 (Hunter) Lecture 2 Summer 2020 38 / 40

Page 111: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Challenge Problem

4

Linguistic experts!

Design a program that counts the numberof plural nouns in a list of nouns. Thinkabout:

what the input is,

what the output is, and

how you can determine if a noun isplural.

Note: To simplify the problem, assume allplural nouns end in “s”.

CSci 127 (Hunter) Lecture 2 Summer 2020 39 / 40

Page 112: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and stringsI Some arithmeticI String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 113: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loops

I range()I Variables: ints and stringsI Some arithmeticI String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 114: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()

I Variables: ints and stringsI Some arithmeticI String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 115: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and strings

I Some arithmeticI String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 116: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and stringsI Some arithmetic

I String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 117: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and stringsI Some arithmeticI String concatenation

I Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 118: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and stringsI Some arithmeticI String concatenationI Functions: ord() and chr()

I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 119: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and stringsI Some arithmeticI String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40

Page 120: CSci 127: Introduction to Computer Science€¦ · CSci 127 (Hunter) Lecture 2 Summer 2020 1 / 40. Frequently Asked Questions From previous semesters Am I only responsible for reading

Recap

In Python, we introduced:

I For-loopsI range()I Variables: ints and stringsI Some arithmeticI String concatenationI Functions: ord() and chr()I String Manipulation

CSci 127 (Hunter) Lecture 2 Summer 2020 40 / 40


Recommended