Define a function num_letters(...) that evaluates a string consisting of numbers, letters, and symbols that returns the total number of letters of the alphabet (upper and lowercase) in the string. If there are no letters in the function, then it should return the message "no way".
As an example, the following code fragment:
st1="aihj{234][o" print (num_letters(st1))
should produce the output:
5
def num_letters(s): count = 0 for ch in s: if ch.isalpha(): count += 1 if count == 0: return "no way" else: return count st1 = "aihj{234][o" print(num_letters(st1))
Define a function num_letters(...) that evaluates a string consisting of numbers, letters, and symbols that returns...
Define a function called AddEvenPosDigs(string), which takes a string (with symbols and characters) as an argument, and returns an integer. This function should add the digits of a string that are in an even position. If there are no digits, the function should return -1. As an example, the following code fragment: string = "a12b056jk"; result=AddEvenPosDigs(string); print(result) should produce the output: 8
D.1 [3] Define a function called funD1...) that receives a string and returns a new string with all the characters in the original string in an EVEN position. As an example, the following code fragment: print (funD1('abcde')) should produce the output: ace D.2 [6] Define a function funD2(...) which receives a list ist that contains single letters, single digits and single special characters and the list contains at least one element of each type). The function returns a string that...
Define a function named double_add_digits_in_string(...) which receives a string as a parameter and returns the sum of the digits multiplied by two. A solution using a loop is expected. As an example, the following code fragment: total = double_add_digits_in_string("xx1xx2xx3xx") print (total) should produce the output: 12
Define a function funD2(...) which receives a list lst that contains single letters, single digits and single special characters (and the list contains at least one element of each type). The function returns a string that contains the last letter and the last special character of the list, where each is repeated as many times as the sum of all digits in the list. As an example, the following code fragment: lst = ["a","b","c", 1, 2, "$","%"] print (funD2(lst)) should...
Define a function add_nums_x_pos_given_list_nums (..) which receives a list that is guaranteed to only have numbers (or the empty list) and returns the sum of each number multiplied by the position where the number is. (In the case of the empty list the function it will return 0) For example add_nums_x_pos_given_list_nums ([10,20,30]) will return the value 80 which is the result of adding: 0 * 10 (10 is in position 0 in the list) + 1 * 20 + 2...
PYTHON define a function called fav_colours(): which receives a list of strings of lowercasecolours: the list some words will repeat, one colour or many, long list or short, Will always be lowercase - return a list of lists containing unique colours and integer numbers describing the amount of times those colours repeated As an example, the following code fragment: colours = ['blue', 'red', 'red', 'red', 'green'] colours , numbers = fav_colours(colours) print(colours) print(numbers) should produce the output: ['blue', 'red', 'green']...
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 language:Python
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 Language Python
Define a function called repeat_middle which receives as parameter one string (with at least one character), and it should return a new string which will have the middle character/s in the string repeated as many times as the length of the input (original) string. Notice that if the original string has an odd number of characters there is only one middle character. If, on the other hand, if the original string has an even number of characters then there will...
[III.4] You are given a boolean expression consisting of a string of the symbols 'true', 'false', and', 'or', and 'xor'. Count the number of ways to parenthesize the expression such that it will evaluate to true. For example, there is only 1 way to parenthesize 'true and false xor true' such that it evaluates to true. Complete the following tasks. [III.4a] Show the parenthesization of the example such that evaluate to true. 'true and false xor true' [III.4b] Show the optimal substructure...