1 / 20

CompSci 101 Introduction to Computer Science

Learn how to solve problems using strings and lists in computer science. Topics covered include string splicing, making decisions with if statements, looping over structures, and more.

kathyj
Download Presentation

CompSci 101 Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CompSci 101Introduction to Computer Science Jan 31, 2017 Prof. Rodger compsci101 spring17

  2. How to teach pancake Flipping • http://www.youtube.com/watch?v=W_gxLKSsSIE • Is this computer science? http://bit.ly/zykOrh • For longer, more complex robotic tasks • http://www.youtube.com/watch?v=4usoE981e7I compsci101 spring17

  3. Lab 3 this week • String splicing • word = ”go duke” • print word[3:5] + word[0] • Making decisions – if • Lists – [”orange”, ”kiwi”, ”lemon” ] compsci101 spring17

  4. Announcements • Reading and RQ6 due next time • Assignment 2 due today, Assignment 3 out • APT 2 due on Thursday • APT Quiz 1 next Sunday 6pm-Tuesday 10pm • You pick 3 hours to take it during that time • Today: • Problem solving: Strings, Lists • Looping over structures (characters, words) and building something

  5. Assignment 3 • Turtles • Creative • Earthquakes • Data from last 30 days around the world • Example - Find the largest earthquake compsci101 spring17

  6. How to solve problems with different cases? • Keep score in a video game? • Different points for different tasks? • Translate a book from English to Spanish? • Different words, different rules • Identify proteins in strands of DNA? • Start codon: atg Stop Codon: tag • Different cases with Pancake APT? • In Python use: if, else ,elif compsci101 spring17

  7. More on Strings • Strings are indexed starting at 0 • Example: ‘word’ • Use [x] – to refer to a particular character in word • Use [x:y] to refer to a slice of the string starting at position x and up to but not including position y. Can leave out x or y. o r w d 0 1 2 3 compsci101 spring17

  8. Examplesbit.ly/101s17-0131-1 phrase = "Duke Blue Devils" 1) phrase[0] + phrase[-3] + phrase[-2]*2 2) phrase[5:10] + phrase[:4] 3)(phrase[phrase.find('ev'):]).upper() 4) phrase[-5::2] String fun Crazy import compsci101 spring17

  9. Loop over all characters in a String compsci101 spring17

  10. Loop over string • www.bit.ly/101s17-0131-2 compsci101 spring17

  11. Loop over all words in a list compsci101 spring17

  12. Loop over words • www.bit.ly/101s17-0131-3 compsci101 spring17

  13. Computer Science Alum • Biology and CS • Undergraduate Research - JFLAP • Epic • Now in Med School at Vanderbilt compsci101 spring17

  14. More Computer Science Duke Alums compsci101 spring17

  15. Apply now for a scholarship to go to GHC 2017 compsci101 spring17

  16. compsci101 spring17

  17. LastNameFirst APT http://www.cs.duke.edu/csed/pythonapt/lastnamefirst.html Answer Questions here: bit.ly/101s17-0131-4 compsci101 spring17

  18. Problem Solving to Code7 Step Process • Work small examples by hand • Write down what you did in words (algorithm) • Find Patterns (generalize algorithm) • Work another example by hand (does your algorithm work? If not, go back to 2) • Translate to code • Test several cases • Debug failed test cases

  19. Use 7 step process to solve LastName First compsci101 spring17

More Related