Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Here's a Python function that de-dents a string of Python code as much as possible while preserving relative indentation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | def dedent(s: str) -> str: # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring empty lines min_indent = float('inf') for line in lines: if line.strip(): # Skip empty or whitespace-only lines indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # If all lines were empty or min_indent is infinite if min_indent == float('inf'): return s # Remove minimum indentation from each line dedented_lines = [] for line in lines: if line.strip(): # If line has content dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Join lines back together with original line endings return '\n'.join(dedented_lines) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # Example 1: Basic indentation code1 = """ def hello(): print("Hello") for i in range(3): print(i) """ print(dedent(code1)) # Output: # def hello(): # print("Hello") # for i in range(3): # print(i) # Example 2: With empty lines code2 = """ def test(): x = 1 y = 2 return x + y """ print(dedent(code2)) # Output: # def test(): # x = 1 # # y = 2 # # return x + y # Example 3: Already unindented code3 = """ def main(): pass """ print(dedent(code3)) # Output: # def main(): # pass |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | def dedent(s: str) -> str: # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring empty lines min_indent = float('inf') for line in lines: if line.strip(): # Skip empty or whitespace-only lines indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # If all lines were empty or min_indent is infinite if min_indent == float('inf'): return s # Remove minimum indentation from each line dedented_lines = [] for line in lines: if line.strip(): # If line has content dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Join lines back together with original line endings return '\n'.join(dedented_lines) def main(): # Example 1: Basic indentation code1 = """ def hello(): print("Hello") for i in range(3): print(i) """ print("Example 1:") print(dedent(code1)) print() # Example 2: With empty lines code2 = """ def test(): x = 1 y = 2 return x + y """ print("Example 2:") print(dedent(code2)) print() # Example 3: Already unindented code3 = """ def main(): pass """ print("Example 3:") print(dedent(code3)) if __name__ == "__main__": main() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | def dedent(s: str) -> str: # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring empty lines min_indent = float('inf') for line in lines: if line.strip(): # Skip empty or whitespace-only lines indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # If all lines were empty or min_indent is infinite if min_indent == float('inf'): return s # Remove minimum indentation from each line dedented_lines = [] for line in lines: if line.strip(): # If line has content dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Join lines back together with original line endings return '\n'.join(dedented_lines) def main(): # Example 1: Basic indentation code1 = """ def hello(): print("Hello") for i in range(3): print(i) """ print("Example 1:") print(dedent(code1)) print() # Example 2: With empty lines code2 = """ def test(): x = 1 y = 2 return x + y """ print("Example 2:") print(dedent(code2)) print() # Example 3: Already unindented code3 = """ def main(): pass """ print("Example 3:") print(dedent(code3)) if __name__ == "__main__": main() answer = dedent(''' print("hello") print("world") if True: print("true") else: print("false")''') expected = """print("hello") print("world") if True: print("true") else: print("false")""" assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Example 1: def hello(): print("Hello") for i in range(3): print(i)</p> <p>Example 2: def test(): x = 1</p> <pre><code>y = 2 return x + y </code></pre> <p>Example 3: def main(): pass All tests passed |
Testing if the previous output contains the string All tests passed
: True
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Here's a Python function that de-dents a string of code while preserving relative indentation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring blank lines min_indent = float('inf') for line in lines: if line.strip(): # Skip blank lines indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # Handle case where all lines were blank if min_indent == float('inf'): min_indent = 0 # Remove minimum indentation from each line dedented_lines = [] for line in lines: if line.strip(): # If line is not blank dedented_lines.append(line[min_indent:]) else: dedented_lines.append('') # Join lines back together return '\n'.join(dedented_lines) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # Example 1: Simple indented code code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Output: # def hello(): # print("Hello") # print("World") # Example 2: Code with blank lines code2 = """ def hello(): print("Hello") print("World") """ print(dedent(code2)) # Output: # def hello(): # print("Hello") # # print("World") # Example 3: Code with varying indentation code3 = """ def hello(): print("Hello") print("World") """ print(dedent(code3)) # Output: # def hello(): # print("Hello") # print("World") |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring blank lines min_indent = float('inf') for line in lines: if line.strip(): # Skip blank lines indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # Handle case where all lines were blank if min_indent == float('inf'): min_indent = 0 # Remove minimum indentation from each line dedented_lines = [] for line in lines: if line.strip(): # If line is not blank dedented_lines.append(line[min_indent:]) else: dedented_lines.append('') # Join lines back together return '\n'.join(dedented_lines) def main(): # Example 1: Simple indented code code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Example 2: Code with blank lines code2 = """ def hello(): print("Hello") print("World") """ print(dedent(code2)) # Example 3: Code with varying indentation code3 = """ def hello(): print("Hello") print("World") """ print(dedent(code3)) if __name__ == "__main__": main() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring blank lines min_indent = float('inf') for line in lines: if line.strip(): # Skip blank lines indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # Handle case where all lines were blank if min_indent == float('inf'): min_indent = 0 # Remove minimum indentation from each line dedented_lines = [] for line in lines: if line.strip(): # If line is not blank dedented_lines.append(line[min_indent:]) else: dedented_lines.append('') # Join lines back together return '\n'.join(dedented_lines) def main(): # Example 1: Simple indented code code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Example 2: Code with blank lines code2 = """ def hello(): print("Hello") print("World") """ print(dedent(code2)) # Example 3: Code with varying indentation code3 = """ def hello(): print("Hello") print("World") """ print(dedent(code3)) if __name__ == "__main__": main() answer = dedent(''' print("hello") print("world") if True: print("true") else: print("false")''') expected = """print("hello") print("world") if True: print("true") else: print("false")""" assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
def hello():
print("Hello")
print("World")
def hello():
print("Hello")
print("World")
def hello():
print("Hello")
print("World")
All tests passed
Testing if the previous output contains the string All tests passed
: True
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Here's a Python function that dedents a string of Python code maximally while ignoring blank lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | def dedent(s): # Split into lines and filter out empty lines for determining indent lines = s.splitlines() non_empty_lines = [line for line in lines if line.strip()] # If no non-empty lines, return original string if not non_empty_lines: return s # Find minimum indentation among non-empty lines min_indent = min(len(line) - len(line.lstrip()) for line in non_empty_lines) # Remove that amount of indentation from all lines (except empty ones) dedented_lines = [] for line in lines: if line.strip(): # If line is not empty dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Rejoin the lines return '\n'.join(dedented_lines) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # Example 1: Basic indentation code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Output: # # def hello(): # print("Hello") # print("World") # Example 2: With empty lines code2 = """ def test(): x = 1 y = 2 z = 3 """ print(dedent(code2)) # Output: # # def test(): # x = 1 # # y = 2 # z = 3 # Example 3: Mixed indentation code3 = """ def foo(): return 42 def bar(): return 43 """ print(dedent(code3)) # Output: # # def foo(): # return 42 # def bar(): # return 43 |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | def dedent(s): # Split into lines and filter out empty lines for determining indent lines = s.splitlines() non_empty_lines = [line for line in lines if line.strip()] # If no non-empty lines, return original string if not non_empty_lines: return s # Find minimum indentation among non-empty lines min_indent = min(len(line) - len(line.lstrip()) for line in non_empty_lines) # Remove that amount of indentation from all lines (except empty ones) dedented_lines = [] for line in lines: if line.strip(): # If line is not empty dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Rejoin the lines return '\n'.join(dedented_lines) def main(): # Example 1: Basic indentation code1 = """ def hello(): print("Hello") print("World") """ print("Example 1:") print(dedent(code1)) # Example 2: With empty lines code2 = """ def test(): x = 1 y = 2 z = 3 """ print("\nExample 2:") print(dedent(code2)) # Example 3: Mixed indentation code3 = """ def foo(): return 42 def bar(): return 43 """ print("\nExample 3:") print(dedent(code3)) if __name__ == "__main__": main() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | def dedent(s): # Split into lines and filter out empty lines for determining indent lines = s.splitlines() non_empty_lines = [line for line in lines if line.strip()] # If no non-empty lines, return original string if not non_empty_lines: return s # Find minimum indentation among non-empty lines min_indent = min(len(line) - len(line.lstrip()) for line in non_empty_lines) # Remove that amount of indentation from all lines (except empty ones) dedented_lines = [] for line in lines: if line.strip(): # If line is not empty dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Rejoin the lines return '\n'.join(dedented_lines) def main(): # Example 1: Basic indentation code1 = """ def hello(): print("Hello") print("World") """ print("Example 1:") print(dedent(code1)) # Example 2: With empty lines code2 = """ def test(): x = 1 y = 2 z = 3 """ print("\nExample 2:") print(dedent(code2)) # Example 3: Mixed indentation code3 = """ def foo(): return 42 def bar(): return 43 """ print("\nExample 3:") print(dedent(code3)) if __name__ == "__main__": main() answer = dedent(''' print("hello") print("world") if True: print("true") else: print("false")''') expected = """print("hello") print("world") if True: print("true") else: print("false")""" assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Example 1: def hello(): print("Hello") print("World") Example 2: def test(): x = 1</p> <pre><code>y = 2 z = 3 </code></pre> <p>Example 3: def foo(): return 42 def bar(): return 43 All tests passed |
Testing if the previous output contains the string All tests passed
: True
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Here's a Python function that de-dents a string of Python code maximally while ignoring blank lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring blank lines min_indent = float('inf') for line in lines: # Skip blank lines if line.strip() == '': continue # Count leading spaces indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # Handle case where all lines are blank if min_indent == float('inf'): min_indent = 0 # Remove the minimum indentation from each line dedented_lines = [] for line in lines: if line.strip() == '': # Preserve blank lines without modification dedented_lines.append(line) else: dedented_lines.append(line[min_indent:]) # Join lines back together return '\n'.join(dedented_lines) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # Example 1: Basic indentation code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Output: # def hello(): # print("Hello") # print("World") # Example 2: With blank lines code2 = """ def hello(): print("Hello") print("World") """ print(dedent(code2)) # Output: # def hello(): # print("Hello") # # print("World") # Example 3: Already minimal indentation code3 = """ def hello(): print("Hello") """ print(dedent(code3)) # Output: # def hello(): # print("Hello") # Example 4: All blank lines code4 = """ """ print(dedent(code4)) # Output: # |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring blank lines min_indent = float('inf') for line in lines: # Skip blank lines if line.strip() == '': continue # Count leading spaces indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # Handle case where all lines are blank if min_indent == float('inf'): min_indent = 0 # Remove the minimum indentation from each line dedented_lines = [] for line in lines: if line.strip() == '': # Preserve blank lines without modification dedented_lines.append(line) else: dedented_lines.append(line[min_indent:]) # Join lines back together return '\n'.join(dedented_lines) def main(): # Example 1: Basic indentation code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Example 2: With blank lines code2 = """ def hello(): print("Hello") print("World") """ print(dedent(code2)) # Example 3: Already minimal indentation code3 = """ def hello(): print("Hello") """ print(dedent(code3)) # Example 4: All blank lines code4 = """ """ print(dedent(code4)) if __name__ == "__main__": main() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation, ignoring blank lines min_indent = float('inf') for line in lines: # Skip blank lines if line.strip() == '': continue # Count leading spaces indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # Handle case where all lines are blank if min_indent == float('inf'): min_indent = 0 # Remove the minimum indentation from each line dedented_lines = [] for line in lines: if line.strip() == '': # Preserve blank lines without modification dedented_lines.append(line) else: dedented_lines.append(line[min_indent:]) # Join lines back together return '\n'.join(dedented_lines) def main(): # Example 1: Basic indentation code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Example 2: With blank lines code2 = """ def hello(): print("Hello") print("World") """ print(dedent(code2)) # Example 3: Already minimal indentation code3 = """ def hello(): print("Hello") """ print(dedent(code3)) # Example 4: All blank lines code4 = """ """ print(dedent(code4)) if __name__ == "__main__": main() answer = dedent(''' print("hello") print("world") if True: print("true") else: print("false")''') expected = """print("hello") print("world") if True: print("true") else: print("false")""" assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
1 2 3 4 5 6 7 8 9 10 | def hello(): print("Hello") print("World")</p> <p>def hello(): print("Hello")</p> <pre><code>print("World") </code></pre> <p>def hello(): print("Hello") All tests passed |
Testing if the previous output contains the string All tests passed
: True
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Write a python function `dedent(str)` that takes as input a string of python code and de-dents it maximally. Lines that are entirely blank don't count.
Here's a Python function that de-dents a string of Python code maximally while preserving relative indentation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation across non-empty lines min_indent = float('inf') for line in lines: # Skip empty lines if line.strip(): # Count leading spaces indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # If all lines were empty or min_indent is infinity if min_indent == float('inf'): return s # Remove the minimum indentation from all lines dedented_lines = [] for line in lines: if line.strip(): # Remove minimum indentation from non-empty lines dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Join lines back together return '\n'.join(dedented_lines) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # Example 1 code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Output: # def hello(): # print("Hello") # print("World") # Example 2 code2 = """ class Test: def method(self): return True def other(self): return False """ print(dedent(code2)) # Output: # class Test: # def method(self): # return True # # def other(self): # return False # Example 3 - Empty lines are preserved code3 = """ def test(): print("test") """ print(dedent(code3)) # Output: # def test(): # # print("test") |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation across non-empty lines min_indent = float('inf') for line in lines: # Skip empty lines if line.strip(): # Count leading spaces indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # If all lines were empty or min_indent is infinity if min_indent == float('inf'): return s # Remove the minimum indentation from all lines dedented_lines = [] for line in lines: if line.strip(): # Remove minimum indentation from non-empty lines dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Join lines back together return '\n'.join(dedented_lines) def main(): # Example 1 code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Example 2 code2 = """ class Test: def method(self): return True def other(self): return False """ print(dedent(code2)) # Example 3 - Empty lines are preserved code3 = """ def test(): print("test") """ print(dedent(code3)) if __name__ == "__main__": main() |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | def dedent(s): # Split into lines lines = s.splitlines() # Find minimum indentation across non-empty lines min_indent = float('inf') for line in lines: # Skip empty lines if line.strip(): # Count leading spaces indent = len(line) - len(line.lstrip()) min_indent = min(min_indent, indent) # If all lines were empty or min_indent is infinity if min_indent == float('inf'): return s # Remove the minimum indentation from all lines dedented_lines = [] for line in lines: if line.strip(): # Remove minimum indentation from non-empty lines dedented_lines.append(line[min_indent:]) else: # Keep empty lines as is dedented_lines.append(line) # Join lines back together return '\n'.join(dedented_lines) def main(): # Example 1 code1 = """ def hello(): print("Hello") print("World") """ print(dedent(code1)) # Example 2 code2 = """ class Test: def method(self): return True def other(self): return False """ print(dedent(code2)) # Example 3 - Empty lines are preserved code3 = """ def test(): print("test") """ print(dedent(code3)) if __name__ == "__main__": main() answer = dedent(''' print("hello") print("world") if True: print("true") else: print("false")''') expected = """print("hello") print("world") if True: print("true") else: print("false")""" assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
1 2 3 4 5 6 7 8 9 10 11 12 13 | def hello(): print("Hello") print("World")</p> <p>class Test: def method(self): return True</p> <pre><code>def other(self): return False </code></pre> <p>def test():</p> <pre><code>print("test") </code></pre> <p>All tests passed |
Testing if the previous output contains the string All tests passed
: True