Hello I have been study python for the pass few months and can't seem to figure out how to get the code below to work. The could runs but I am not receiving the output I was expected. I know strings are immutable, at first I kept using list function a realized that was incorrect but im stuck at thE moment. Not sure if I need to use a for loop to iterate through the string?
def function(input_string):
output_string = ''
if len(input_string)> 6:
return input_string[1:] #Should return the string starting at index 1
elif input_string.count('e') > 2:
return input_string.count('e') #should return the count of 'E'
elif input_string.isdigit():
return input_string % 2
#Should if string is a digit halve it example input_string = '4224' should be output_string'2114'
else:
return input_string[-1:0] #Should reverse the string outoutput_string='Ecetem'
return output_string
input_string = 'metecE'
output_string = function(input_string)
print(output_string)
I've tried using a for loop. This is a practice question for a test. The criteria after the # are required and it has to be in a function. I will not be allowed to change any of the code beside the logic I have with if-else statement. Any help with be greatly appreciate. I really want to figure out what I did incorrectly.
input_string[::-1]. If the start is less than the end, and you did not specify a negative increment, it will return an empty string. When you doinput_string[-1:0], Python still wants to do forward indexing. It doesn't try to "sort" the indexes.