The __main__ Guard, Explained in Code

Easy ⏱ 8 min 82% acceptance ★★★★★ 4.6
Write a module-style snippet: a function banner() returning 'reporting tool', and a main() that returns banner().upper() — with the standard if __name__ == '__main__': guard calling main() so importing the file never triggers execution. (Your submitted code is the module itself.)

Examples

Example 1
Input
imported: nothing prints; run directly: main() executes
Output
'REPORTING TOOL' from main()
Explanation

The guard distinguishes import from direct execution.

Constraints

  • Include the exact guard line.
  • main() must call banner().

Topics

Modules & Packages__name__

Companies

InfosysTCSCapgemini

Hints

Hint 1

__name__ is '__main__' only when run as a script.

Hint 2

The guard goes at the bottom of the file.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.