Write a function that takes two strings, s1, and s2:
- It prints "s1 in s2" if s1 is in s2
- It prints "s2 in s1" if s2 is in s1
- It prints "both" if s1 is in s2 and s2 in s1 (meaning both are the same)
- It prints "neither" otherwise
Write a function that takes one string and returns True if it is greater (comes after) than "Pse". It returns False otherwise.
Write a function which takes two strings, s1 and s2, and it concatenates the first 3
characters of s1 with the last 2 characters of s2 and returns it.
Example:
>>> concatenate_strings("power", "owl")
'powwl'
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, 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, less_than_n(word, n), that returns True if word has less than n letters, False otherwise.
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 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", 2): | ||
| is_char("xerxe", "x", 3): | ||
| is_char("carralluke", "r", 3): |
Complete execution flow of the following program
def ends_with_the_same_letter(s1, s2): return s1[-1] == s2[-1]
Complete execution flow of the following program
def return_char(s, n): return s[n] return_char('llapushnik', 4) return_char('llaushe', 2 + 4)