Top Banner
Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
21

Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Dec 13, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Exam Prep and Wrap-Up

Intro to Computer Science

CS1510, Section 2

Dr. Sarah Diesburg

Page 2: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Topics for today

Information on the exams Questions remaining from Tuesday’s Lab? Several examples from your book Some string formatting examples Split()

Page 3: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Exam Information

Two exams next week Focuses on chapters 1-4 Includes material from the lectures and from

the readings.

Page 4: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Exam Information

Monday, October 14 In class, written exam Mixture of multiple choice, short answer, and

essay. 100 points Closed book, closed notes

Page 5: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Exam Information

Tuesday, October 15 In lab, programming exam Five small scripts 125 points (25 points each) Closed book, MOSTLY closed notes

One page (one sided) of handwritten notes May also use the built in Python documentation (really

not helpful if you haven’t used it before then)

Page 6: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Advice for the Tests

These things can make the difference of whether you pass or fail this class when studying Go through each class days notes and example

programs on the website Practice coding over and over by going through

your labs!!! This is the only way to really learn. Review vocabulary and concepts by reading

the book!!

6

Page 7: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Again…

The only way you can become comfortable with a toolset is to practice Understanding what a power drill does will not

help you much if you don’t practice using it It’s the same for code Practicing coding will make you more familiar with

the coding structures necessary to code more quickly

Patterns will emerge, it will become easier

7

Page 8: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Questions about Tuesday’s Lab Did you understand the explanations I made

on both the string-based and math-based solutions?

Remaining issues?

Page 9: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Questions over PA05?

9

Page 10: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Anything you want me to go over?

10

Page 11: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

String Wrap-Up

Find a Letter Enumerate Split Palindromes

Page 12: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

4.1 Find a Letter

river = 'Mississippi'

target = input('Input character to find: ')

for index in range(len(river)): #for each index

if river[index] == target: #check

print( "Letter found at index: ", index )

break # stop searching

else:

print( 'Letter',target,'not found in',river)

Page 13: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Enumerate Function

The enumerate function prints out two values: the index of an element and the element itself

Can use it to iterate through both the index and element simultaneously, doing dual assignment

Page 14: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

4.2-4.3 Enumeration

# print first occurrence

river = 'Mississippi'

target = input('Input character to find: ')

for index,letter in enumerate(river):

if letter== target: #check

print ("Letter found at index: ", index)

break # stop searching

else:

print( 'Letter',target,'not found in',river)

Page 15: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

4.2-4.3 Enumeration

# print all occurrences

river = 'Mississippi'

target = input('Input character to find: ')

for index,letter in enumerate(river):

if letter== target: #check

print ("Letter found at index: ", index )

# break # stop

else:

print( 'Letter',target,'not found in',river)

Page 16: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Split Function

The split function will take a string and break it into multiple new string parts depending on what the argument character is.

By default, if no argument is provided, split is on any whitespace character (tab, blank, etc.)

You can assign the pieces with multiple assignment if you know how many pieces are yielded.

Page 17: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Reorder a Name

origName = ‘John Marwood Cleese’

first,mid,last = origName.split()

name = last + ‘, ‘ + first + ‘ ‘ + mid

print (name)

Page 18: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Palindromes and the Rules A palindrome is a string that prints the same

forward and backwards Same implies that:

case does not matter punctuation is ignored

“Madam I’m Adam” is thus a palindrome

Page 19: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Lower Case and Punctuation Every letter is converted using the lower

method Import string, brings in a series of predefined

sequences (string.digits, string.punctuation, string.whitespace)

We remove all non-wanted characters with the replace method. First arg is what to replace, the second the replacement.

Page 20: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Part 1 of Palindrome

# first partimport stringoriginalString = input('Input a string:')modifiedStr = originalString.lower()badChars = string.whitespace + string.punctuationfor char in modifiedStr: if char in badChars: # remove bad modifiedStr = modifiedStr.replace(char,'')

Page 21: Exam Prep and Wrap-Up Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Part 1 of Palindrome

# second partif modifiedStr == modifiedStr[::-1]: # palindrome ? print( 'The original string is: {}\n\ the modified string is: {}\n\ the reversal is: {}\n\ The string is a palindrome'.format( originalString, modifiedStr, modifiedStr[::-1]))else: # similar printing for not a palindrome