Calvin (Deutschbein)
W4Fri: 19 Sep
for letter in "cs":
print(letter)
c
s
for letter in "abcdef":
print(letter)
a
b
c
d
e
f
vowels = "aeiou"
for letter in "abcdef":
print(letter, letter in vowels)
a True
b False
c False
d False
e True
f False
vowels = "aeiou"
for letter in "abcdef":
if letter not in vowels:
print(letter)
b
c
d
f
for letter in "cs":
print(letter)
for i in range(len('cs')):
print('cs'[i]) # get it? csi?
word = "lied"
# word = "veil"
for i in range(len(word)):
print(word[i])
l
i
e
d
word = "lied"
# word = "veil"
for index in range(len(word)):
if word[index] == 'i':
# check the letter *before* the 'i'
print(word[index-1])
l
# word = "lied"
word = "veil"
for index in range(len(word)):
if word[index] == 'i':
# check the letter *before* the 'i'
print(word[index-1])
e
def i_before_e(word:str) -> bool:
for index in range(len(word)):
if word[index] == 'i':
# check the letter *before* the 'i'
if word[index-1] == 'e':
return False
print(i_before_e('veil'))
False
print(i_before_e('lied'))
None
def i_before_e(word:str) -> bool:
for index in range(len(word)):
if word[index] == 'i':
# check the letter *before* the 'i'
if word[index-1] == 'e':
return False
return True # this is indented the same as the 'for' loop
>>> i_before_e('icee') # its a disaster
def i_before_e(word:str) -> bool:
for index in range(1, len(word)): # fix is here.
if word[index] == 'i' and word[index-1] == 'e':
return False
return True # this is indented the same as the 'for' loop
h | e | l | l | o | w | o | r | l | d | |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
-10 | -9 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 |
print("hello world"[-3])
print("hello world"[8])
r
r
if word[index] == 'i' and word[index-1] == 'e':
abcs = 'abcdefghijklmnopqrstuvwxyz'
for i in range(9,20,3):
print(i, abcs[i])
9 j
12 m
15 p
18 s
abcs = 'abcdefghijklmnopqrstuvwxyz'
new_word = ""
for i in range(9,20,3):
new_word += abcs[i]
print(new_word)
jmps
new_word = ""
for i in range(9,20,3):
new_word += abcs[i]
new_word = abcs[9:20:3]
print(abcs[9:20:3])
print("hello world"[:5])
print("hello world"[5:])
print("deeps"[::-1])
|
hello
world
speed
|
def remove_space(s:str) -> str: # given string, make new string
for i in range(len(s)): # check each letter
if s[i] == " ": # if letter is space...
return s[:i] + s[i+1:] # before space + after space
print(remove_space("hello world"))
helloworld
def remove_space(s:str) -> str: # given string, make new string
for i in range(len(s)): # check each letter
if s[i] == " ": # if letter is space...
return s[:i] + s[i+1:] # before space + after space
print(remove_space("world"))
def space_to_underscore(s:str) -> str:
for i in range(len(s)): # check each letter
if s[i] == " ": # if letter is space...
return s[:i] + "_" + s[i+1:]
return s # return 's' if no spaces
print(space_to_underscore("hello world"))
print(space_to_underscore("world")
hello_world
world
def spaces_to_underscores(s:str) -> str:
for i in range(len(s)): # check each letter
if s[i] == " ": # if letter is space...
return s[:i] + "_" + spaces_to_underscores(s[i+1:])
return s # return 's' if no spaces
print(spaces_to_underscores("thats me espresso"))
thats_me_espresso
def n_spaces_before(n:int,s:str) -> NoneType: # print -> None
print(n * ' ', s) # test - that is 'n times space plus s'
def spaces_to_underscores(s):
for i in range(len(s)):
if s[i] == " ":
return s[:i] + "_" + spaces_to_underscores(s[i+1:])
return s