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 has_common_letters(word1, word2) that returns True if the two words share at least one common letter, 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'
Encapsulate this code: word = 'banana'
count = 0
for letter in word:
if letter == 'a':
count = count + 1
print(count)
in a function named count, and generalize it so that it accepts the string and the letter as arguments.
Result should be printed, not returned
Define a function, less_than_n(word, n), that returns True if word has less than n letters, False otherwise.
Define a function that takes a string, a character and an integer, word, char and i, and returns True if character of word with index i is equal to char.
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 return_char(s, n):
index = len(s) - n
return s[index]
Given the above script, what are the results of the following expressions:
| return_char("python", 1): | ||
| return_char("python", 3): |
Complete execution flow of the following program
>>>
Complete execution flow of the following program
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 dosmth('add')