Crib Sheet Python: Continue
Crib Sheet Python: Continue
break continue
len(s) returns how many characters in a string s
if __name__ == "__main__":
doctest.testmod() print(I, end = “ “)
you can access a character in a string s with s[i] where i is the index of the
character (starts from 0 and the range is (-len(s) to len(s)-1)
Output: 1 2 3 4
-len(i) is the index len(s)-i
1 2 3 4 6 7 8 9 10
To select a slice we do s[first:second:step] first(inc) second(exc) with a step of 1
s = 'bananas' Yo whats
for char in s:
up
if char == 'a':
return sum
def is_a_vowel(c):
vowels = 'aeiou'
return len(c) == 1 and c in vowels
def only_vowels(s):
def greetings():
import math
def get_substring(s, i, j):
if i < 0 or j < 0 or i >= len(s) or j >= len(s): def greatest_common_divisor(x, y):
then you need to use math.sin(90)
return '' while x != y:
from math import * if x > y:
# A possible solution is to use slicing: x=x-y
# return s[i
then: j +you
1] can use sin(90) else:
y=y-x
# otheriwise
importusemath
a loopas m
substring = '' return x
for indexthen
in range(i, j+1):to use m.sin(90)
you need
substring += s[index] def least_common_multiple(x, y):
return substring
product = abs(x * y)