Write a function, that takes a word and a character,
word and char, and returns the index of char where it appears in word.
If there are more than one char, it should return the first index.
Example:
>>> first_index('ani', 'n')
1
>>> first_index('nana', 'n')
0
>>> first_index('nana', 'a')
1
Restrictions: You cannot use find or index string methods.
Write a function, add_indices, that takes a word and two characters,
word, char1 and char2, and returns sum of indices where char1 and char2 appear
first in word. Example:
>>> add_indices('ani', 'a', 'n')
1
>>> add_indices('nana baba', 'b', 'a')
6
Restrictions: The body of of the function should have only one line
Write a function which takes a string, s, as argument, and prints only its characters with index less than 5 (not including 5).
Define a function, fifth_from_end(word), that returns word's fifth character from the end.
Define a function, more_than_n(word, n), that returns True if word has more than n letters.
Define a function that takes a string and returns its first character.
There is a string method, lower, which returns lowercase version of the string.
Write a function, to_lower, which takes a string as argument and returns the lowercase
version of the string.
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'): |
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): |
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
>>>