Write your solution in the PF_solution.py file in the PE package
01:07:27
Problem Statement:
Description: Consider an input string
Z2FuZHJhLnNocmF2YW5p
Write a Python function that accepts input_string as a parameter and returns an output_string based on the
logic below
• The second character of the input_string, which is a digit if it is equal to the length of the input_string
then initialize output_string with 'A'
For Example: If the input_string is '7akes1', then the output string would be 'A' since the second character
of the input_string which is '7' is equal to the length of the input_string
• Otherwise, if the input_string contains exactly two 'a', then initialize output string with '8
You're being proctored
For Example: If the input_string is '24activate then output_string would be 'B'
Note: Do case-sensitive comparison
• Otherwise, If the input_string contains infosys, then initialize output string with
For Example: If the input_string is 42infosys Mysore, then the output_string would
Note: Do case-sensitive comparison
}
NJASVmYmdd M2VNOMZZTUSYTEYOTES/Gdhbmky
Answers
Answer:
the PE package
01:07:27
Problem Statement:
Description: Consider an input string
Z2FuZHJhLnNocmF2YW5p
Write a Python function that accepts input_string as a parameter and returns an output_string based on the
logic below
• The second character of the input_string, which is a digit if it is equal to the length of the input_string
then initialize output_string with 'A'
For Example: If the input_string is '7akes1', then the output string would be 'A' since the second character
of the input_string which is '7' is equal to the length of the input_string
• Otherwise, if the input_string contains exactly two 'a', then initialize output string with '8
You're being proctored
For Example: If the input_string is '24activate then output_string would be 'B'
Note: Do case-sensitive comparison
• Otherwise, If the input_string contains infosys, then initialize output string with
For Example: If the input_string is 42infosys Mysore, then the output_string would
Note: Do case-sensitive comparison
}
NJASVmYmdd M2VNOMZZTUSYTEYOTES/Gdhbmky
Explanation:
the PE package
01:07:27
Problem Statement:
Description: Consider an input string
Z2FuZHJhLnNocmF2YW5p
Write a Python function that accepts input_string as a parameter and returns an output_string based on the
logic below
• The second character of the input_string, which is a digit if it is equal to the length of the input_string
then initialize output_string with 'A'
For Example: If the input_string is '7akes1', then the output string would be 'A' since the second character
of the input_string which is '7' is equal to the length of the input_string
• Otherwise, if the input_string contains exactly two 'a', then initialize output string with '8
You're being proctored
For Example: If the input_string is '24activate then output_string woul
Note: Do case-sensitive comparison
• Otherwise, If the input_string contains infosys, then initialize output string with
For Example: If the input_stringi
Answer:
def reverse(s):
if len(s) == 0:
return s
else:
return reverse(s[1:]) + s[0]
s = input("enter the string\n")
print ("The original string is : ",end="")
print (s)
print ("The recursively reversed output string is : ",end="")
print (reverse(s))
Explanation:
Time complexity : O(n)
Auxiliary Space : O(n)
- The string is supplied as an input to a recursive function in the code above in order to reverse the string. If the string's length is equal to 0, which is the function's default condition, the string is returned.
- If the value is not 0, the reverse function is used again to slice the string up until the first character and concatenate it to the end of the sliced string.
#SPJ2