Skip to content

[Feature] Implement --random Flag #4

@SthembisoMfusi

Description

@SthembisoMfusi

Description

Add a --random flag that displays information for a random Pokémon.

Current Behavior

PyDex only accepts Pokémon names as arguments.

Expected Behavior

When --random is used, PyDex should pick a random Pokémon ID (1-1025) and display its information.

Usage Examples

python pokedex.py --random
python pokedex.py -r  # short form

Implementation Steps

  1. Import the random module
  2. Modify the argument parsing to check for --random or -r
  3. Generate a random number between 1 and 1025
  4. Use that number to fetch Pokémon data by ID instead of name
  5. Update the usage message to show the new option

Skills Required

  • Basic Python knowledge
  • Understanding of command-line arguments
  • Working with random numbers

What You'll Learn

  • Command-line argument parsing
  • Random number generation
  • API usage with different parameters
  • Code organization

Testing

Run the command multiple times to ensure you get different Pokémon:

  • python pokedex.py --random
  • python pokedex.py -r
  • Test that it still works with regular Pokémon names

Hints

  • Use random.randint(1, 1025) to generate random numbers
  • Check if sys.argv[1] is --random or -r
  • The API URL can use either name or ID: https://pokeapi.co/api/v2/pokemon/25

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions