Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to CS Nov 13, 2017.

Similar presentations


Presentation on theme: "Intro to CS Nov 13, 2017."— Presentation transcript:

1 Intro to CS Nov 13, 2017

2 Today’s Objectives Strings

3 Strings >>> “Hello" # String with Double Quote ‘Hello'
>>> ‘world' # String with single Quote ‘world' >>> msg1=‘Hello ' >>> msg2=“World!" >>> msg = msg1 + msg2 # add 2 strings TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

4 Strings >>> msg2=“y'all" # This displays single quote
>>> msg = msg1 + msg2 >>> msg2='y"all' >>> msg2=“y”all" # what does this print??? >>> msg2=“y\”all” # Add a double quote >>> msg2=‘y\’all’ # Add a single quote TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

5 Strings >>> msg = msg1 * 3 + msg2 # Duplicate with *
>>> msg=‘Hel\nlo’ # Add a newline >>> msg2=‘Hel\tlo’ # add a tab TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

6 Strings - extracting characters with []
>>> letters = 'abcdefghijklmnopqrstuvwxyz' >>> letters[0] 'a' >>> letters[1] 'b' >>> letters[-1] 'z' >>> letters[-2] 'y' >>> letters[25] >>> letters[5] 'f' TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

7 Strings - extracting characters with []
>>> letters = 'abcdefghijklmnopqrstuvwxyz' >>> letters[0] 'a' >>> letters[1] 'b' >>> letters[-1] 'z' >>> letters[-2] 'y' >>> letters[25] >>> letters[5] 'f' TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

8 Strings msg = msg1 * 3 + msg2 # Duplicate with *
msg1=‘Hel\nlo’ # Add a newline msg2=‘Hel\tlo’ # add a tab TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

9 Strings len(<string>) - get length
letters = 'abcdefghijklmnopqrstuvwxyz' len(letters) empty=“” len(empty) <string>.split(<split_character>) - split a string using <split_character> passed as parameter. If no character, passed, defaults to SPACE todos = 'get gloves,get mask,give cat vitamins,call ambulance' todos.split(',') todos.split() TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

10 Strings String is a sequence of characters. Individual characters in a string can be accessed by [<index>] fruit=‘banana’ fruit[0] 'b' fruit[2] 'n' fruit[5] 'a' TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

11 Strings - slice with [ start : end : step ]
mechanism to extract a substring (a part of a string) from a string start - starting offset (character at this offset included) end - end offset (characters unto one before this offset ) step - optional step size

12 • [ start :] specifies from the start offset to the end.
• [: end ] specifies from the beginning to the end offset minus 1. • [ start : end ] indicates from the start offset to the end offset minus 1. [ start : end : step ] extracts from the start offset to the end offset minus 1, skipping characters by step. [:] extracts the entire sequence from start to end.

13 letters = 'abcdefghijklmnopqrstuvwxyz' letters[:]
TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

14 letters = 'abcdefghijklmnopqrstuvwxyz'
7

15 letters = 'abcdefghijklmnopqrstuvwxyz' letters[-6:-2] 'uvwx'
'ahov' letters[4:20:3] 'ehknqt' letters[19::4] 'tx' TIMING 4 MINUTES (39 TOTAL) ACTUAL – ran out of time Now let’s take what we’ve learned and apply it to making a song Here’s an example with the start of Mary had A Little Lamb How can you execute a single program element? (double click) Individual notes can be played by double clicking on them. How can you execute a set of elements? You can tell what will execute together by them sticking together What white bar to know where you are inserting pull the bottom off to differentiate from ‘move’ You can predict what will fit where by shape. How do you delete an element? How do you reorder elements Notice the “Stop Script” block at the end. It’s always good programming practice to always have a “stop script” block and the end of any script so that you clearly indicate it’s the end. In BYOB, you don’t necessarily need to have it there, but if you learn other language it will be very important to always make sure you clearly indicate the end of scripts 7

16 letters = 'abcdefghijklmnopqrstuvwxyz'
'afkpu' letters[-1::-1] 'zyxwvutsrqponmlkjihgfedcba' letters[::-1]


Download ppt "Intro to CS Nov 13, 2017."

Similar presentations


Ads by Google