Write a function that takes two strings, and
- if they are equal, it returns "They are equal"
- if they are not equal, it returns "They are not equal"
Write a function which takes a string, s, as argument, and prints its characters with odd index (1, 3, 5, ...) each in a new line.
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, to_upper which takes a string as argument and returns the uppercase version of the string.
Write a function which takes three strings, s1, s2 and chars and returns True if all characters
of chars appear s1 or s2 (at least in one of them).
Example:
>>> appear_in_one_of_them("abc", "bcd", "abcd")
True
>>> appear_in_one_of_them("school", "home", "hlm")
True
>>> appear_in_one_of_them("world", "earth", "wem")
False
Define a function, more_than_5(word), that returns True if word has more than 5 letters, False otherwise.
def return_char(s, n):
return s[n]
Given the above script, what are the results of the following expressions:
| return_char('llukar', 0): | ||
| return_char('xerxe', 3): | ||
| return_char('carralluke', 1): |
def dosmth(s, char):
c = 0
for i in range(len(s)):
if s[i] == char:
c = c + i
return c
Given the above script, what are the results of the following expressions:
| dosmth('baba', 'b'): | ||
| dosmth('nana', 'a'): |
Complete execution flow of the following program
def return_char(s, n): return s[n] return_char('poroj', 2) return_char('mujdin', 1)
Complete execution flow of the following program
>>>