# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # [START gae_python38_app] # [START gae_python3_app] import logging from flask import Flask, request # Enable cloud debugger try: import googleclouddebugger googleclouddebugger.enable() except ImportError: pass # Adjust logging level to INFO logging.basicConfig(level=logging.INFO) # If `entrypoint` is not defined in app.yaml, App Engine will look for an app # called `app` in `main.py`. app = Flask(__name__) # There is a bug in the code. class StringProcessor(): def __init__(self, string): self._string = string def Reverse(self): if self._string == '': return '' chars = [c for c in self._string] left = 0 right = len(chars) - 1 while True: tmp = chars[left] chars[left] = chars[right] chars[right] = tmp if left >= right: break left += 1 right -= 1 return ''.join(chars) @app.route('/reverse_string', methods=['GET']) def ReverseString(): try: s = str(request.args.get('string')) except Exception as e: print(e) return 'Not a valid string!' current = StringProcessor(s).Reverse() expected = s[::-1] return '''
| Program Output: | {} |
|---|---|
| Correct Output: | {} |