Python Exercises
  • Fundamentals
    • Introduction To Programming
    • Functions
      • Execute order 66
      • Hello, goodbye
      • Opening arguments (2)
      • Do my homework (2)
      • The Answer (2)
      • Print Banner (2)
        • Starter Code
        • Tests
      • FITB Average
      • Skyline (2)
      • The Number N (3)
      • Mystery Numbers (3)
      • Perimeter Parameter (3)
      • String Times
  • Practical Programming
  • Codingbat
  • Codingbat (Input/Output)
  • Dynamic Programming
  • Ccc Problems
  • Functional Python
  • Solutions
Python Exercises
  • »
  • Fundamentals »
  • Functions »
  • Print Banner
  • View page source

Print Banner¶

Topic:

defining a function

Requirements:

  • calling a function

The starter text will print out a some ASCII art. Select all the lines and press tab to indent them all once. Right on top of the indented print statements, define a function called print_banner. The definition line should be def print_banner():

To ensure you did it correctly, call the function and run it.

Check out the ASCII art generator.

Starter Code¶

print("  _    _      _ _         __          __        _     _ _ ")
print(" | |  | |    | | |        \ \        / /       | |   | | |")
print(" | |__| | ___| | | ___     \ \  /\  / /__  _ __| | __| | |")
print(" |  __  |/ _ \ | |/ _ \     \ \/  \/ / _ \| '__| |/ _` | |")
print(" | |  | |  __/ | | (_) |     \  /\  / (_) | |  | | (_| |_|")
print(" |_|  |_|\___|_|_|\___( )     \/  \/ \___/|_|  |_|\__,_(_)")
print("                      |/                                  ")

Tests¶

from exercise.fixtures import captured_output, source_code_matches

from main import print_banner


def test_function_defined_properly():
    assert len(source_code_matches(r'def\s+print_banner\s*\(\s*\)\s*:\s*')) == 1


def test_print_banner(capsys):
    print_banner()
    captured = capsys.readouterr()
    assert captured.out == """  _    _      _ _         __          __        _     _ _ 
 | |  | |    | | |        \ \        / /       | |   | | |
 | |__| | ___| | | ___     \ \  /\  / /__  _ __| | __| | |
 |  __  |/ _ \ | |/ _ \     \ \/  \/ / _ \| '__| |/ _` | |
 | |  | |  __/ | | (_) |     \  /\  / (_) | |  | | (_| |_|
 |_|  |_|\___|_|_|\___( )     \/  \/ \___/|_|  |_|\__,_(_)
                      |/                                  
"""
Next Previous

© Copyright 2020, Mr. Gallo.

Built with Sphinx using a theme provided by Read the Docs.