Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to list all files ending with '.txt' in the current directory.
Linux CLI
ls [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '?txt' matches only files with exactly one character before 'txt'.
Using 'txt*' matches files starting with 'txt', not ending.
Using '[a-z].txt' matches only files with a single lowercase letter before '.txt'.
✗ Incorrect
The wildcard '*.txt' matches all files ending with '.txt'.
2fill in blank
mediumComplete the code to list files with exactly three characters and ending with '.log'.
Linux CLI
ls [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*.log' matches any number of characters, not exactly three.
Using '*.???' matches files with any name and three-character extension.
Using '?*.log' matches files with at least one character before '.log', not exactly three.
✗ Incorrect
The pattern '???.log' matches files with exactly three characters before '.log'.
3fill in blank
hardFix the error in the code to list files starting with 'data' followed by any single character and ending with '.csv'.
Linux CLI
ls data[1].csv Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' matches zero or more characters, not exactly one.
Using '[]' or '[?]' is incorrect syntax for matching a single character.
✗ Incorrect
The '?' wildcard matches exactly one character, so 'data?.csv' matches files like 'data1.csv'.
4fill in blank
hardFill both blanks to list files that start with 'log', followed by a digit between 1 and 3, and ending with '.txt'.
Linux CLI
ls log[1][2].txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '?' after '[1-3]' matches exactly one character, but we want any number.
Using '[a-z]' matches letters, not digits.
Using '*' alone does not restrict the digit.
✗ Incorrect
The pattern '[1-3]*' matches files starting with 'log', then a digit 1 to 3, then any characters, ending with '.txt'.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps filenames to their extensions for files with names starting with 'img' and extensions '.jpg' or '.png'.
Linux CLI
files = ['img1.jpg', 'img2.png', 'img3.gif'] result = { [1]: [2] for file in files if file.startswith('img') and file.endswith([3]) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'file.split('.')' returns a list, not the extension string.
Using a single string in endswith instead of a tuple misses multiple extensions.
Using wrong keys or values in the dictionary comprehension.
✗ Incorrect
The comprehension maps each filename to its extension by splitting on '.' and filtering files ending with '.jpg' or '.png'.