You can download this code by clicking the button below.
This code is now available for download.
This code defines a simple command-line interface with two commands: one to add two numbers and print the result, and another to reverse a given word.
Technology Stack : Click, Python Standard Library
Code Type : Command line tool
Code Difficulty : Intermediate
import click
import random
@click.group()
def cli():
"""A simple command-line interface for a random task."""
pass
@cli.command()
@click.argument('number', type=int)
def add(number):
"""Add two numbers and print the result."""
result = number + number
click.echo(f'The sum is {result}')
@cli.command()
@click.argument('word', type=str)
def reverse(word):
"""Reverse a given word."""
reversed_word = word[::-1]
click.echo(reversed_word)
def main():
cli()
if __name__ == '__main__':
main()