If you have any doubts please comment below. Please give upvote if you like this.
Answer : p
there fore the output of following code is "p".
Explanation :
Instalize my_string with "alpha"
after we call the method get_letter_index() with arguments letter
"p" and string my_str
Inside method :
for loop itterates from i =0 to length of the given
string
check if i =0:
string[0] == "p" false because
string[0] is "a" so loop itterate
check if i =1 :
string[1] == "p" false because
string[1] is "l" so loop itterate
check if i =2 :
string[2] == "p" true because
string[2] is "p" so loop returns i i.e(i=2)
we assign that value to p_index i.e p_index = 2
finally we print the my_string[p_index] i.e the value of my_string[2] is "p"
What would be the output of the following code? def get_letter_index(letter, string): returns the index of...
def second_index(a_list, number): Accepts a list of integers and an integer, and returns the index of the SECOND occurrence of the integer in the list. It returns None if the number does not occur two or more times in the list. Example 1: second_index ([2,34,3,45,34,45,3,3), 3) returns 6 Example 2: second_index( [2,34,3,45,34,45,3,3), 45) returns 5 Example 3: second_index ( [2,34,3,45,134,45,3,3), 134) returns None Example 4: second_index( [2,34,3,45, 134,45,3,3), 100) returns None return None def hasEveryLetter(s): #s is a string Returns...
Paste this code into a new file and find the errors. The most frequent letter in the user_string is H. # Function displays the character that appears most frequently # in the string. If several characters have the same highest # frequency, displays the first character with that frequency. def main(): # Set up local variables count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' index = 0 frequent = 0 # Receive user input. user_string = 'Who where what why how' for ch...
LOVOU AWN 1. def remove_all_from_string(word, letter): i=0 3. while i<len(word)-1: if word[i] = letter: num = word.find(letter) word - word[:num] + word[num+1:] i=0 i=i+1 return word 10 print remove_all_from_string("hello", "1") 5 points Status: Not Submitted Write a function called remove_all_from_string that takes two strings, and returns a copy of the first string with all instances of the second string removed. This time, the second string may be any length, including 0. Test your function on the strings "bananas" and "na"....
def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...
this python code below is to find the longest common subsequence from two input string !!! however it give me the wrong answer, can any one fix it thanks def lcs(s1, s2): matrix = [["" for x in range(len(s2))] for x in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: if i == 0 or j == 0: matrix[i][j] = s1[i] else: matrix[i][j] = matrix[i-1][j-1] + s1[i] else: matrix[i][j] = max(matrix[i-1][j], matrix[i][j-1], key=len) cs =...
5. What is the output of the below program? (14 marks) def Fungsi (xx): print ("x is ", xx) values=[8 ,2 , 6 , 6 ,2 ,6) c=0 for i in range (len (values)): if (values[i] == xx): C=C+1 if c> 0 : print ("Return ", c) return c else: C = 100 print ("Return ", c) return c A = Fungsi (2) print ("The A is ", A) B= Fungsi (6) + Fungsi (7) print ("The Bis", B)
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...
Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX): message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user num = int(input(message)) while num < MINN or num > MAXX: print("Invalid choice!") num = int(input(message)) #return result return num #counts dupes def twoInARow(numbers): ans = "No duplicates next to each...
Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...
Python This is the code we are using: def main (): video_file = open ( 'video_times.txt') list = [] for line in video_file: run_time = float(line) list.append (run_time) print ('Video #', ':', run_time) print(list) sum = 0 for i in range(len(list)): sum = sum + list[i] video_file.close main ( ) The following text is read from the video_times.txt file: Video # 1 : 10.0 Video # 2 : 24.5 Video # 3 : 12.2 Video # 4 :...