Write a function, sub, that takes two numbers and returns the first minus the second.
Write a function, that takes a word and an integer,
word and n, and returns the last n characters of word. Example:
>>> get_substring('gegnisht', 2)
ht
>>> get_substring('tosknisht', 4)
isht
Restrictions:
- You cannot use +, - or *
- The body of the function should have only one line
Write a function, add, that takes two numbers and returns their sum.
Write a function, sub, that takes two numbers and returns the first minus the second.
Write a function, that takes a word and two integers, word, n and e,
and returns characters of word from n - e to n + e (including both).
Example:
>>> middle("robertdeniro", 2, 1)
obe
>>> middle("robertdeniro", 3, 2)
obert
Restrictions:
- You cannot use + or -
- The body of of the function should have only one line
Define a function that takes a string and an integer, word and n, and returns character of word with index n + 1.
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
Write a function the takes one string and returns its last character. You should use len function as part of the index expression.
Define a function has_common_letters(word1, word2) that returns True if the two words share at least one common letter, False otherwise.
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 is_char(word, ch, i):
return word[i] == ch
Given the above script, what are the results of the following expressions:
| is_char("llukar", "u", 3): | ||
| is_char("xerxe", "x", 0): | ||
| is_char("carralluke", "c", 1): |
Complete execution flow of the following program
def are_equal(s1, s2): return s1 == s2
Complete execution flow of the following program
>>>