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
- Import the
random module
- Modify the argument parsing to check for
--random or -r
- Generate a random number between 1 and 1025
- Use that number to fetch Pokémon data by ID instead of name
- 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
Description
Add a
--randomflag that displays information for a random Pokémon.Current Behavior
PyDex only accepts Pokémon names as arguments.
Expected Behavior
When
--randomis 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 formImplementation Steps
randommodule--randomor-rSkills Required
What You'll Learn
Testing
Run the command multiple times to ensure you get different Pokémon:
python pokedex.py --randompython pokedex.py -rHints
random.randint(1, 1025)to generate random numberssys.argv[1]is--randomor-rhttps://pokeapi.co/api/v2/pokemon/25