Define a function contains_letter(word, letter) that returns True if the given letter appears in the word, False otherwise.
ⓘ
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 returns its first character.
ⓘ
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 character of word with index n + 1.
If n is the last index return the first character. Example:
>>> next_char('ani', 1)
"i"
>>> next_char('ani', 2)
"a"
Restrictions: You cannot use + or -
ⓘ
Define a function count_shared_letters(word1, word2) that returns the number of letters from word1 that are found in word2.
ⓘ
def find(word, letter): index = 0 while index < len(word): if word[index] == letter: return index index = index + 1 return -1
Modify find so that it has a third parameter, the index in word where it should start looking.
ⓘ
def return_char(s, n): return s[n]
Given the above script, what are the results of the following expressions:
return_char('zanatek', -1): | |
return_char('zanatek', -4): |
def dosmth(s, chars): res = 0 for index in range(len(s)): if s[index] in chars: res = index + res return res
Given the above script, what are the results of the following expressions:
dosmth('ani', 'ni'): | |
dosmth('psejo', 'eo'): |
Complete execution flow of the following program
def return_char(s, n): return s[n] return_char('mendora', -1) return_char('mendora', -3)
Complete execution flow of the following program
fruit = 'fig' index = 0 while index < len(fruit): letter = fruit[index] print(letter) index = index + 1
'f' 'i' 'g' >>>