Coursera was launched in 2012 by Daphne Koller and Andrew Ng with the goal of giving life-changing learning experiences to students all around the world. In the modern day, Coursera is a worldwide online learning platform that provides anybody, anywhere with access to online courses and degrees from top institutions and corporations.
Using Python to Interact with the Operating System Quiz Answers
Week 1: Getting Your Python On
Practice Quiz: Getting Ready for Python
Q1. Which of the following is the most modern, up-to-date version of Python?
- Python 3
- Python 2
- Python 4
- Anaconda
Q2. Which of the following operating systems is compatible with Python 3?
- Redhat Linux
- Microsoft Windows
- Apple MacOS
- All of the above
Q3. Which of the following operating systems does not run on a Linux kernel?
- Android
- Chrome OS
- Mac OS
- Ubuntu
Q4. If we want to check to see what version of Python is installed, what would we type into the command line? Select all that apply.
- python -V
- python –version
- python –help
- python -v
Q5. What is pip an example of?
- A programming language
- An operating system
- A repository of Python modules
- A Python package manager
Practice Quiz: Running Python Locally
Q1. When your IDE automatically creates an indent for you, this is known as what?
- Code reuse
- Interpreted language
- Syntax highlighting
- Code completion
Q2. Can you identify the error in the following code?
- The function is not indented properly.
- The y variable is not calling the numpy module properly.
- The shebang line is not necessary.
- numpy is not imported correctly because as is used.
Q2. Which type of programming language is read and converted to machine code before runtime, allowing for more efficient code?
- Object-oriented language
- Compiled language
- Interpreted language
- Intermediate code
Q3. Which of the following is not an IDE or code editor?
- Eclipse
- pip
- Atom
- PyCharm
Q4. What does the PATH variable do?
- Tells the operating system where to find executables
- Returns the current working directory
- Holds the command line arguments of your Python program in a list
- Tells the operating system where to cache frequently used files;
Practice Quiz: Automation
Q1. At a manufacturing plant, an employee spends several minutes each hour noting uptime and downtime for each of the machines they are running. Which of the following ideas would best automate this process?
- Provide a tablet computer to the employee to record uptime and downtime
- Hire an extra employee to track uptime and downtime for each machine
- Add an analog Internet of Things (IoT) module to each machine, in order to detect their power states, and write a script that records uptime and downtime, reporting hourly
- Add an analog IoT module to each machine, in order to detect their power states, and attach lights that change color according to the power state of the machine
Q2. One important aspect of automation is forensic value. Which of the following statements describes this term correctly?
- It is important for automated processes to leave extensive logs so when errors occur, they can be properly investigated.
- It’s important to have staff trained on how automation processes work so they can be maintained and fixed when they fail.
- It’s important to organize logs in a way that makes debugging easier.
- It’s important to remember that 20% of our tasks as system administrators is responsible for 80% of our total workload.
Q3. An employee at a technical support company is required to collate reports into a single file and send that file via email three times a day, five days a week for one month, on top of his other duties. It takes him about 15 minutes each time. He has discovered a way to automate the process, but it will take him at least 10 hours to code the automation script. Which of the following equations will help them decide whether it’s worth automating the process?
- if [10 hours to automate > (15 minutes * 60 times per month)] then automate
- if [10 hours to automate < (15 minutes * 60 times per month)] then automate
- if [(10 hours to automate + 15 minutes) > 60 times per month)] then automate
- [(10 hours to automate / 60 times per month) < 15 minutes]
Q4. A company is looking at automating one of their internal processes and wants to determine if automating a process would save labor time this year. The company uses the formula [time_to_automate < (time_to_perform * amount_of_times_done) to decide whether automation is worthwhile. The process normally takes about 10 minutes every week. The automation process itself will take 40 hours total to complete. Using the formula, how many weeks will it be before the company starts saving time on the process?
- 6 weeks
- 2 weeks
- 24 weeks
- 240 weeks
Q5. Which of the following are valid methods to prevent silent automation errors? (Check all that apply)
- Email notifications about errors
- Internal issue tracker entries
- Constant human oversight
- Regular consistency checks
Peer Graded Assessment
Using Python to interact with the Operating System Week 02 Quiz Answers
Practice Quiz: Managing Files & Directories
Q1. The create_python_script function creates a new python script in the current working directory, adds the line of comments to it declared by the ‘comments’ variable, and returns the size of the new file. Fill in the gaps to create a script called “program.py”.
def create_python_script(filename):
comments = “# Start of a new Python program”
with open(filename, ‘w’) as file:
filesize = file.write(comments)
return(filesize)
print(create_python_script(“program.py”))
Output:
31
Q2. The new_directory function creates a new directory inside the current working directory, then creates a new empty file inside the new directory, and returns the list of files in that directory. Fill in the gaps to create a file “script.py” in the directory “PythonPrograms”.
import os
def new_directory(directory, filename):
# Before creating a new directory, check to see if it already exists
if os.path.isdir(directory) == False:
os.mkdir(directory)
# Create the new file inside of the new directory
os.chdir(directory)
with open (filename, ‘w’) as file:
file.write(“”)
# Return the list of files in the new directory
os.chdir(‘..’)
return os.listdir(directory)
print(new_directory(“PythonPrograms”, “script.py”))
Output:
[‘script.py’]
Q3. Which of the following methods from the os module will create a new directory?
- path.isdir()
- listdir()
- mkdir()
- chdir()
Q4. The file_date function creates a new file in the current working directory, checks the date that the file was modified, and returns just the date portion of the timestamp in the format of yyyy-mm-dd. Fill in the gaps to create a file called “newfile.txt” and check the date that it was modified.
import os
import datetime
def file_date(filename):
# Create the file in the current directory
with open (filename,’w’) as file:
pass
timestamp = os.path.getmtime(filename)
# Convert the timestamp into a readable format, then into a string
timestamp = datetime.datetime.fromtimestamp(timestamp)
# Return just the date portion
# Hint: how many characters are in “yyyy-mm-dd”?
return (“{}”.format(timestamp.strftime(“%Y-%m-%d”)))
print(file_date(“newfile.txt”))
# Should be today’s date in the format of yyyy-mm-dd
Output:
2020-07-18
Q5. The parent_directory function returns the name of the directory that’s located just above the current working directory. Remember that ‘..’ is a relative path alias that means “go up to the parent directory”. Fill in the gaps to complete this function.
import os
def parent_directory():
# Create a relative path to the parent
# of the current working directory
relative_parent = os.path.abspath(‘..’)
# Return the absolute path of the parent directory
return relative_parent
print(parent_directory())
Output:
/
Practice Quiz: Reading & Writing CSV Files
Q1. We’re working with a list of flowers and some information about each one. The create_file function writes this information to a CSV file. The contents_of_file function reads this file into records and returns the information in a nicely formatted block. Fill in the gaps of the contents_of_file function to turn the data in the CSV file into a dictionary using DictReader.
import os
import csv
# Create a file with data in it
def create_file(filename):
with open(filename, “w”) as file:
file.write(“name,color,type\n”)
file.write(“carnation,pink,annual\n”)
file.write(“daffodil,yellow,perennial\n”)
file.write(“iris,blue,perennial\n”)
file.write(“poinsettia,red,perennial\n”)
file.write(“sunflower,yellow,annual\n”)
# Read the file contents and format the information about each row
def contents_of_file(filename):
return_string = “”
# Call the function to create the file
create_file(filename)
# Open the file
with open(filename) as file:
# Read the rows of the file into a dictionary
reader = csv.DictReader(file)
# Process each item of the dictionary
for row in reader:
return_string += “a {} {} is {}\n”.format(row[“color”], row[“name”], row[“type”])
return return_string
#Call the function
print(contents_of_file(“flowers.csv”))
Note
This question throws:
Output:
a pink carnation is annual
a yellow daffodil is perennial
a blue iris is perennial
a red poinsettia is perennial
a yellow sunflower is annual
Q2. Using the CSV file of flowers again, fill in the gaps of the contents_of_file function to process the data without turning it into a dictionary. How do you skip over the header record with the field names?
import os
import csv
# Create a file with data in it
def create_file(filename):
with open(filename, “w”) as file:
file.write(“name,color,type\n”)
file.write(“carnation,pink,annual\n”)
file.write(“daffodil,yellow,perennial\n”)
file.write(“iris,blue,perennial\n”)
file.write(“poinsettia,red,perennial\n”)
file.write(“sunflower,yellow,annual\n”)
# Read the file contents and format the information about each row
def contents_of_file(filename):
return_string = “”
# Call the function to create the file
create_file(filename)
# Open the file
with open(filename, “r”) as file:
# Read the rows of the file
rows = csv.reader(file)
# Process each row
for row in list(rows)[1:]:
name, color, types = row
# Format the return string for data rows only
return_string += “a {} {} is {}\n”.format(color, name, types)
return return_string
#Call the function
print(contents_of_file(“flowers.csv”))
Output:
a pink carnation is annual
a yellow daffodil is perennial
a blue iris is perennial
a red poinsettia is perennial
a yellow sunflower is annual
Q3. In order to use the writerows() function of DictWriter() to write a list of dictionaries to each line of a CSV file, what steps should we take? (Check all that apply)
- Create an instance of the DictWriter() class
- Write the fieldnames parameter into the first row using writeheader()
- Open the csv file using with open
- Import the OS module
Q4. Which of the following is true about unpacking values into variables when reading rows of a CSV file? (Check all that apply)
- We need the same amount of variables as there are columns of data in the CSV
- Rows can be read using both csv.reader and csv.DictReader
- An instance of the reader class must be created first
- The CSV file does not have to be explicitly opened
Q5. If we are analyzing a file’s contents to correctly structure its data, what action are we performing on the file?
- Writing
- Appending
- Parsing
- Reading;
Reading and Writing Files
Using Python to interact with the Operating System Graded Assessment Answers
Sources
Using Python to interact with the Operating System Week 03 Quiz Answers
Practice Quiz: Regular Expressions
Q1. When using regular expressions, which of the following expressions uses a reserved character that can represent any single character?
- re.findall(f.n, text)
- re.findall(f*n, text)
- re.findall(fu$, text)
- re.findall(^un, text)
Q2. Which of the following is NOT a function of the Python regex module?
- re.search()
- re.match()
- re.findall()
- re.grep()
Q3. The circumflex [^] and the dollar sign [$] are anchor characters. What do these anchor characters do in regex?
- Match the start and end of a word.
- Match the start and end of a line
- Exclude everything between two anchor characters
- Represent any number and any letter character, respectively
Q4. When using regex, some characters represent particular types of characters. Some examples are the dollar sign, the circumflex, and the dot wildcard. What are these characters collectively known as?
- Special characters
- Anchor characters
- Literal characters
- Wildcard characters
Q5. What is grep?
- An operating system
- A command for parsing strings in Python
- A command-line regex tool
- A type of special character;
Practice Quiz: Basic Regular Expressions
Q1. The check_web_address function checks if the text passed qualifies as a top-level web address, meaning that it contains alphanumeric characters (which includes letters, numbers, and underscores), as well as periods, dashes, and a plus sign, followed by a period and a character-only top-level domain such as “.com”, “.info”, “.edu”, etc. Fill in the regular expression to do that, using escape characters, wildcards, repetition qualifiers, beginning and end-of-line characters, and character classes.
import re
def check_web_address(text):
pattern = r’^[\w\._-]*\.[A-Za-z]*$’
result = re.search(pattern, text)
return result != None
print(check_web_address(“gmail.com”)) # True
print(check_web_address(“[email protected]“)) # False
print(check_web_address(“www.Coursera.org”)) # True
print(check_web_address(“web-address.com/homepage”)) # False
print(check_web_address(“My_Favorite-Blog.US”)) # True
Output:;
True
False
True
False
True
Q2. The check_time function checks for the time format of a 12-hour clock, as follows: the hour is between 1 and 12, with no leading zero, followed by a colon, then minutes between 00 and 59, then an optional space, and then AM or PM, in upper or lower case. Fill in the regular expression to do that. How many of the concepts that you just learned can you use here?
import re
def check_time(text):
pattern = r’^(1[0-2]|1?[1-9]):([0-5][0-9])( ?([AaPp][Mm]))’
result = re.search(pattern, text)
return result != None
print(check_time(“12:45pm”)) # True
print(check_time(“9:59 AM”)) # True
print(check_time(“6:60am”)) # False
print(check_time(“five o’clock”)) # False
Output:;
True
True
False
False
Q3. The contains_acronym function checks the text for the presence of 2 or more characters or digits surrounded by parentheses, with at least the first character in uppercase (if it’s a letter), returning True if the condition is met, or False otherwise. For example, “Instant messaging (IM) is a set of communication technologies used for text-based communication” should return True since (IM) satisfies the match conditions.” Fill in the regular expression in this function:
import re
def contains_acronym(text):
pattern = r’\(+[A-Z0-9][a-zA-Z]*\)’
result = re.search(pattern, text)
return result != None
print(contains_acronym(“Instant messaging (IM) is a set of communication technologies used for text-based communication”)) # True
print(contains_acronym(“American Standard Code for Information Interchange (ASCII) is a character encoding standard for electronic communication”)) # True
print(contains_acronym(“Please do NOT enter without permission!”)) # False
print(contains_acronym(“PostScript is a fourth-generation programming language (4GL)”)) # True
print(contains_acronym(“Have fun using a self-contained underwater breathing apparatus (Scuba)!”)) # True
Output:
True
True
False
True
True
Q4. What does the “r” before the pattern string in re.search(r”Py.*n”, sample.txt) indicate?
- Raw strings
- Regex
- Repeat
- Result
Q5. What does the plus character [+] do in regex?
- Matches plus sign characters
- Matches one or more occurrences of the character before it
- Matches the end of a string
- Matches the character before the [+] only if there is more than one
Q6. Fill in the code to check if the text passed includes a possible U.S. zip code, formatted as follows: exactly 5 digits, and sometimes, but not always, followed by a dash with 4 more digits. The zip code needs to be preceded by at least one space, and cannot be at the start of the text.
import re
def check_zip_code (text):
result = re.search(r’ \d{5}| \d{5}-\d{4}’, text)
return result != None
print(check_zip_code(“The zip codes for New York are 10001 thru 11104.”)) # True
print(check_zip_code(“90210 is a TV show”)) # False
print(check_zip_code(“Their address is: 123 Main Street, Anytown, AZ 85258-0001.”)) # True
print(check_zip_code(“The Parliament of Canada is at 111 Wellington St, Ottawa, ON K1A0A9.”)) # False
Output:
True
False
True
False;
Practice Quiz: Advanced Regular Expressions
Q1. We’re working with a CSV file, which contains employee information. Each record has a name field, followed by a phone number field, and a role field. The phone number field contains U.S. phone numbers, and needs to be modified to the international format, with “+1-” in front of the phone number. Fill in the regular expression, using groups, to use the transform_record function to do that.
import re
def transform_record(record):
new_record = re.sub(r”,(\d{3})”,r”,+1-\1″,record)
return new_record
print(transform_record(“Sabrina Green,802-867-5309,System Administrator”))
# Sabrina Green,+1-802-867-5309,System Administrator
print(transform_record(“Eli Jones,684-3481127,IT specialist”))
# Eli Jones,+1-684-3481127,IT specialist
print(transform_record(“Melody Daniels,846-687-7436,Programmer”))
# Melody Daniels,+1-846-687-7436,Programmer
print(transform_record(“Charlie Rivera,698-746-3357,Web Developer”))
# Charlie Rivera,+1-698-746-3357,Web Developer
Output:
Sabrina Green,+1-802-867-5309,System Administrator
Eli Jones,+1-684-3481127,IT specialist
Melody Daniels,+1-846-687-7436,Programmer
Charlie Rivera,+1-698-746-3357,Web Developer
Q2. The multi_vowel_words function returns all words with 3 or more consecutive vowels (a, e, i, o, u). Fill in the regular expression to do that.
import re
def multi_vowel_words(text):
pattern = r’\w+[aiueo]{3,}\w+’
result = re.findall(pattern, text)
return result
print(multi_vowel_words(“Life is beautiful”))
# [‘beautiful’]
print(multi_vowel_words(“Obviously, the queen is courageous and gracious.”))
# [‘Obviously’, ‘queen’, ‘courageous’, ‘gracious’]
print(multi_vowel_words(“The rambunctious children had to sit quietly and await their delicious dinner.”))
# [‘rambunctious’, ‘quietly’, ‘delicious’]
print(multi_vowel_words(“The order of a data queue is First In First Out (FIFO)”))
# [‘queue’]
print(multi_vowel_words(“Hello world!”))
# []
Output:
[‘beautiful’]
[‘Obviously’, ‘queen’, ‘courageous’, ‘gracious’]
[‘rambunctious’, ‘quietly’, ‘delicious’]
[‘queue’]
[]
Q3. When capturing regex groups, what datatype does the groups method return?
- A string
- A tuple
- A list
- A float
Q4. The transform_comments function converts comments in a Python script into those usable by a C compiler. This means looking for text that begins with a hash mark (#) and replacing it with double slashes (//), which is the C single-line comment indicator.
For the purpose of this exercise, we’ll ignore the possibility of a hash mark embedded inside of a Python command, and assume that it’s only used to indicate a comment. We also want to treat repetitive hash marks (###), (####), etc., as a single comment indicator, to be replaced with just (//) and not (#//) or (//#). Fill in the parameters of the substitution method to complete this function:
import re
def transform_comments(line_of_code):
result = re.sub(r’\#{1,}’, r’//’, line_of_code)
return result
print(transform_comments(“#### Start of program”))
# Should be “// Start of program”
print(transform_comments(” number = 0 ### Initialize the variable”))
# Should be ” number = 0 // Initialize the variable”
print(transform_comments(” number += 1 # Increment the variable”))
# Should be ” number += 1 // Increment the variable”
print(transform_comments(” return(number)”))
# Should be ” return(number)”
Output:
// Start of program
number = 0 // Initialize the variable
number += 1 // Increment the variable
return(number)
Q5. The convert_phone_number function checks for a U.S. phone number format: XXX-XXX-XXXX (3 digits followed by a dash, 3 more digits followed by a dash, and 4 digits), and converts it to a more formal format that looks like this: (XXX) XXX-XXXX. Fill in the regular expression to complete this function.
import re
def convert_phone_number(phone):
result = re.sub(r”\b(\d{3})-(\d{3})-(\d{4})\b”, r”(\1) \2-\3″, phone)
return result
print(convert_phone_number(“My number is 212-345-9999.”)) # My number is (212) 345-9999.
print(convert_phone_number(“Please call 888-555-1234”)) # Please call (888) 555-1234
print(convert_phone_number(“123-123-12345”)) # 123-123-12345
print(convert_phone_number(“Phone number of Buckingham Palace is +44 303 123 7300”)) # Phone number of Buckingham Palace is +44 303 123 7300
Output:
My number is (212) 345-9999.
Please call (888) 555-1234
123-123-12345
Phone number of Buckingham Palace is +44 303 123 7300
Using Python to interact with the Operating System Graded Assessment answers
Using Python to interact with the Operating System Week 04 Quiz Answers
Practice Quiz: Data Streams
Q1. Which command will print out the exit value of a script that just ran successfully?
- echo $PATH
- wc variables.py
- import sys
- echo $?
Q2. Which command will create a new environment variable?
- export
- input
- wc
- env
Q3. Which I/O stream are we using when we use the input function to accept user input in a Python script?
- STDOUT
- STDERR
- STDIN
- SYS
Q4. What is the meaning of an exit code of 0?
- The program ended with an unspecified error.
- The program ended with a ValueError.
- The program ended with a TypeError.
- The program ended successfully.
Q5. Which statements are true about input and raw_input in Python 2? (select all that apply)
- input performs basic math operations.
- raw_input performs basic math operations.
- raw_input gets a string from the user.
- input gets a string from the user.
Practice Quiz: Python Subprocesses
Q1. What type of object does a run function return?
- stdout
- CompletedProcess
- capture_output
- returncode
Q2. How can you change the current working directory where a command will be executed?
- Use the env parameter.
- Use the shell parameter.
- Use the cwd parameter.
- Use the capture_output parameter.
Q3. When a child process is run using the subprocess module, which of the following are true? (check all that apply)
- The child process is run in a secondary environment.
- The parent process is blocked while the child process finishes.
- The parent process and child process both run simultaneously.
- Control is returned to the parent process when the child process ends.
Q4. When using the run command of the subprocess module, what parameter, when set to True, allows us to store the output of a system command?
- cwd
- capture_output
- timeout
- shell
Q5. What does the copy method of os.environ do?
- Creates a new dictionary of environment variables
- Runs a second instance of an environment
- Joins two strings
- Removes a file from a directory
Practice Quiz: Processing Log Files
Q1. You have created a Python script to read a log of users running CRON jobs. The script needs to accept a command line argument for the path to the log file. Which line of code accomplishes this?
- import sys
- syslog=sys.argv[1]
- print(line.strip())
- usernames = {}
Q2. Which of the following is a data structure that can be used to count how many times a specific error appears in a log?
- Dictionary
- Get
- Continue
- Search
Q3. Which keyword will return control back to the top of a loop when iterating through logs?
- Continue
- Get
- With
- Search
Q4. When searching log files using regex, which regex statement will search for the alphanumeric word “IP” followed by one or more digits wrapped in parentheses using a capturing group?
- r”IP \(\d+\)$”
- b”IP \((\w+)\)$”
- r”IP \((\d+)\)$”
- r”IP \((\D+)\)$”
Q5. Which of the following are true about parsing log files? (Select all that apply.)
- Load the entire log files into memory.
- You should parse log files line by line.
- It is efficient to ignore lines that don’t contain the information we need.
- We have to open() the log files first.;
Graded Assessment
Using Python to interact with the Operating System Week 05 Quiz Answers
Practice Quiz: Simple Tests
Q1. You can verify that software code behaves correctly using test _.
- Cases
- Functions
- Loops
- Arguments
Q2. What is the most basic way of testing a script?
- Let a bug slip through.
- Write code to do the tests.
- Codifying tests into the software.
- Different parameters with expected results.
Q3. When a test is codified into its own software, what kind of test is it?
- Unit test
- Integration test
- Automatic test
- Sanity testing
Q4. Using _ simplifies the testing process, allowing us to verify the program’s behavior repeatedly with many possible values.
- integration tests
- test cases
- test-driven development
- interpreter
Q5. The more complex our code becomes, the more value the use of _ provides in managing errors.
- loops
- functions
- parameters
- software testing
Practice Quiz: Other Test Concepts
Q1. In what type of test is the code not transparent?
- Smoke test
- Black-box test
- Test-driven development
- White-box test
Q2. Verifying an automation script works well with the overall system and external entities describes what type of test?
- Integration test
- Regression test
- Load test
- Smoke test
Q3. ensures that any success or failure of a unit test is caused by the behavior of the unit in question, and doesn’t result from some external factor.
- Regression testing
- Integration
- Isolation
- White-box testing
Q4. A test that is written after a bug has been identified in order to ensure the bug doesn’t show up again later is called _
- Load test
- Black-box test
- Smoke test
- Regression test
Q5. What type of software testing is used to verify the software’s ability to behave well under significantly stressed testing conditions?
- Load test
- Black-box test
- Smoke test
- Regression test;
Lab Assessment
Graded Assessment
Scripts
Using Python to interact with the Operating System Week 06 Quiz Answers
Practice Quiz: Advanced Bash Concepts
Q1. Which command does the while loop initiate a task(s) after?
- done
- while
- do
- n=1
Q2. Which line is correctly written to start a FOR loop with a sample.txt file?
- do sample.txt for file
- for sample.txt do in file
- for file in sample.txt; do
- for sample.txt in file; do
Q3. Which of the following Bash lines contains the condition of taking an action when n is less than or equal to 9?
- while [ $n -le 9 ]; dowhile [ $n -le 9 ]; do
- while [ $n -lt 9 ]; do
- while [ $n -ge 9 ]; do
- while [ $n -ot 9 ]; do
Q4. Which of the following statements are true regarding Bash and Python? [Check all that apply]
- Complex scripts are better suited to Python.
- Bash scripts work on all platforms.
- Python can more easily operate on strings, lists, and dictionaries.
- If a script requires testing, Python is preferable.
Q5. The _ command lets us take only bits of each line using a field delimiter.
- cut
- echo
- mv
- sleep
Practice Quiz: Bash Scripting
Q1. Which of the following commands will output a list of all files in the current directory?
- **echo ***
- echo a*
- echo *.py
- echo ?.py
Q2.Which module can you load in a Python script to take advantage of star [*] like in BASH?
- ps
- Glob
- stdin
- Free
Q3. Conditional execution is based on the _ of commands.
- environment variables
- parameters
- exit status
- test results
Q4. What command evaluates the conditions received on exit to verify that there is an exit status of 0 when the conditions are true, and 1 when they are false?
- test
- grep
- echo
- export
Q5. The opening square bracket ([), when combined with the closing square bracket (]), is an alias for which command?
- glob
- test
- export
- ifi;
Practice Quiz: Interacting with the Command Line
Q1. Which of the following commands will redirect errors in a script to a file?
- [email protected]:~$ ./calculator.py >> error_file.txt
- [email protected]:~$ ./calculator.py 2> error_file.txt
- [email protected]:~$ ./calculator.py > error_file.txt
- [email protected]:~$ ./calculator.py < error_file.txt
Q2. When running a kill command in a terminal, what type of signal is being sent to the process?
- PID
- SIGINT
- SIGSTOP
- SIGTERM
Q3. What is required in order to read from standard input using Python?
- echo file.txt
- cat file.txt
- The file descriptor of the STDIN stream
- Stdin file object from sys module
Q4. _ are tokens delivered to running processes to indicate the desired action.
- Signals
- Methods
- Functions
- Commands
Q5. In Linux, what command is used to display the contents of a directory?
- rmdir
- cp
- pwd
- ls
Graded Assessment
Using Python to interact with the Operating System Week 07Quiz Answers
Review:
Based on our knowledge, we urge you to enroll in this course so you can pick up new skills from specialists. It will be worthwhile, we trust.