Write a function that takes two values and returns True if they are equal, or False otherwise.
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 last index.
Example:
>>> last('ani', 'n')
1
>>> last('nana', 'n')
2
>>> last('nana', 'a')
3
Restrictions: You cannot use +, - or ==
Write a function that takes two strings, s1, and s2, and
- if s1 is smaller than s2, it returns "s1 comes before s2"
- if s1 is greater than s2, it returns "s1 comes after s2"
- if s1 is is equal s2, it returns "s1 is equal to s2"
There is a string method capitalize which returns capitalized version of the string.
Write a function which takes a string as argument and returns the capitalized
version of the string.
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 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
Write a function which takes a string, s, as argument, and prints only its characters with index less than 5 (not including 5).
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'): |
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 are_equal(s1, s2): return s1 == s2
Complete execution flow of the following program
def print_numbers(s): for item in s: if item in '0123456789': print(item) print_numbers('a1e2')