Write a function that takes one string and, using slices, returns the first three characters of it.
Define a function, more_than_5(word), that returns True if word has more than 5 letters, False otherwise.
Write a function, add, that takes two numbers and returns their sum.
Write a function, that takes a word and an integer,
word and n, and returns the first n + 3 characters of word. Example:
>>> get_substring('gegnisht', 0)
geg
>>> get_substring('tosknisht', 2)
toskn
Restrictions:
- You cannot use + or -
- The body of of the function should have only one line
Define a function, starts_with_vowel(word), that returns True if the word starts with a vowel, False otherwise.
Write a function which takes a string as argument and prints all its letters in the reverse order (starting from the back of the string) till the letter becomes "m". If the letter becomes "m", you should print it and stop.
Write a function that takes two strings, s1 and s2, and prints all letters that appear in s1 but not in s2.
def slices(word, x, y):
return word[x:y]
Given the above script, what are the results of the following expressions:
| slices("Butch...", 0, 5): | ||
| slices("Butch...", 4, 6): | ||
| slices("Butch...", -4, -1): |
def dosmth(s, chars):
res = ""
for letter in s:
if letter in chars:
res = res + letter
return len(res)
Given the above script, what are the results of the following expressions:
| dosmth('python programming', 'pom'): | ||
| dosmth('python programming', 'arr'): |
Complete execution flow of the following program
>>>
Complete execution flow of the following program
def dosmth(word): s = "" for i in range(len(word)): if i % 2 == 1: s = s + word[i] return s res = dosmth('nkju')