Define a function, string_length(word), that returns the number of characters in the string word.
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 an integer,
word and n, and returns characters of word from n - 2 to n + 2 (including both).
Example:
>>> middle('baushtelle', 2)
baush
>>> middle('baushtelle', 4)
ushte
Restrictions:
- You cannot use + or -
- The body of of the function should have only one line
Define a function that takes a string and returns True if its first character is 'b'.
Write a function, sub, that takes two numbers and returns the result of the first minus the second.
Write a function, that takes a word and a positive integer,
word and n, and returns the n'th character of word.
If n is 1, it should return the first character.
If n is 2, it should return the second character, and so on. Example:
>>> get_char('ani', 1)
"a"
>>> get_char('ani', 3)
"i"
Restrictions:
- You cannot use + or -
- The body of of the function should have only one line
Write a function which takes a string and prints all its letters and their indices,
in the order that they appear, each in a new line. Example:
>>> traverse_string('ani')
0 a
1 n
2 i
Define a function count_shared_letters(word1, word2) that returns the number of letters from word1 that are found in word2.
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): |
def dosmth(line):
count = 0
i = 1
while i < len(line):
if line[i - 1] == line[i]:
count = count + 1
i = i + 1
return count
Given the above script, what are the results of the following expressions:
| dosmth('address'): | ||
| dosmth('apple'): | ||
| dosmth('pse'): |
Complete execution flow of the following program
def is_char(word, ch, i): return word[i] == ch is_char('poroj', 'o', 1) is_char('mujdin', 'd', 3)
Complete execution flow of the following program
def in_both(word1, word2): for letter in word1: if letter in word2: print(letter)