Course 2: USING PYTHON TO INTERACT WITH THE OPERATING SYSTEM

Module 1: Getting your Python On

GOOGLE IT AUTOMATION WITH PYTHON PROFESSIONAL CERTIFICATE

Complete Coursera Study Guide

Last updated:

INTRODUCTION – Getting your Python on

In this module, you’ll learn about the different types of operating systems, and how you can get your python code ready to interact with the operating system. We’ll learn about getting your environment set up and installing additional Python modules that will help you along the way. We’ll rundown interpreted versus compiled language, and how they differ from each other. We’ll dive into the benefits of automation, and point out common pitfalls so you can avoid them. Finally, we’ll learn about Qwiklabs, which will be used for graded assessments.

Learning Objectives

  • Identify the components and functions of an operating system
  • Describe the difference between interpreted and compiled programming languages
  • Explain what an IDE (integrated development environment) is
  • Install and run Python on a local machine
  • List the benefits and pitfalls of automation

Practice Quiz: Getting Ready for Python

1. Which of the following is the most modern, up-to-date version of Python?

  • Python 3 (CORRECT)
  • Python 2
  • Python 4
  • Anaconda

Great job! Python 3 is the latest version of Python, with Python 3.8.0 being released on October 14, 2019.

2. Which of the following operating systems is compatible with Python 3?

  • Redhat Linux
  • Microsoft Windows
  • Apple MacOS
  • All of the above (CORRECT)

Nice work! Python is a cross-platform language. You can use it on Windows, macOS, Linux, and even on lesser-known Unix variants like FreeBSD.

3. Which of the following operating systems does not run on a Linux kernel?

  • Android
  • Chrome OS
  • Mac OS (CORRECT)
  • Ubuntu

Right on! Mac OS is a proprietary operating system designed by Apple and uses a proprietary kernel based on BSD.

4. 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 (CORRECT)
  • python –version (CORRECT)
  • python –help
  • python –v

Awesome! Typing python -V (note the capital V) at the command line will tell you if Python is currently installed and if so, what version.

Awesome! Typing python –version (note the double dashes) at the command line will tell you if Python is currently installed and if so, what version.

5. What is pip an example of?

  • A programming language
  • An operating system
  • A repository of Python modules
  • A Python package manager (CORRECT)

Nice work! pip is a command line tool commonly used as the main method of managing packages in Python.

6. Which of the following is NOT an open-source OS?

  • Ubuntu Linux
  • FreeBSD
  • Android
  • Microsoft Windows (CORRECT)

Right on! The Windows operating system is a proprietary OS developed exclusively by Microsoft.

7. What is the name of the command line tool commonly used to install, update, and remove external Python modules mentioned in the video?

  • pip (CORRECT)
  • PyPI
  • python3 –version
  • conda

Awesome! pip is a cross-platform tool called a package manager used to install, update, or remove external Python modules.

PRACTICE QUIZ: RUNNING PYTHON LOCALLY

1. When your IDE automatically creates an indent for you, this is known as what?

  • Interpreted language
  • Code reuse
  • Code completion (CORRECT)
  • Syntax highlighting

Nicely done! Code completion is an IDE feature that takes educated guesses about what you might be trying to type next, and offers suggestions to complete it for you.

2. Can you identify the error in the following code?

#!/usr/bin/env python3
import numpy as np


def numpyArray():
    x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
    y = numpy.array([[3, 6, 2], [9, 12, 8]], np.int32)
    return x*y
print(numpyArray())
  • The function is not indented properly.
  • numpy is not imported correctly because as is used.
  • The shebang line is not necessary.
  • The y variable is not calling the numpy module properly. (CORRECT)

Nice job! While the x variable is calling numpy using its declared local name, y is not using the local name. This will result in an error.

3. Which type of programming language is read and converted to machine code before runtime, allowing for more efficient code?

  • Object-oriented language
  • Compiled language (CORRECT)
  • Interpreted language
  • Intermediate code

Awesome! A compiled language is translated into code readable by the target machine during development using a compiler.

4. Which of the following is not an IDE or code editor?

  • Eclipse
  • pip (CORRECT)
  • Atom
  • PyCharm

Right on! The package manager pip is used in Python to install packages from repositories such as PyPI.

5. What does the PATH variable do?

  • Tells the operating system where to find executables (CORRECT)
  • 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

Nice work! The PATH variable tells the operating system where to find executables.

6. Which of the following programming languages are interpreted languages?

  • Java and C#
  • Python and Javascript (CORRECT)
  • C++ and Go
  • C and Rust

Nailed it! Interpreted languages trade off slightly slower runtime performance—removing the need for compiling—by using programs called interpreters to execute the code.

7. What is the purpose of using a shebang line in a Python file?

  • To tell the operating system where to find programs to execute.
  • To tell the operating system to execute a file in the current directory.
  • To specify beforehand what command to use when running the script. (CORRECT)
  • To make the specified file executable by changing permissions.

Keep it up! Inserting a shebang line (such as #!/usr/bin/env python3) as the first line tells the operating system what command we want to use to execute the script.

8. Proper code reuse is important, so let’s see if you were paying attention. Which of the following lines will allow you to use the datetime module in your script?

  • use datetime
  • using datetime
  • date_time = datetime
  • import datetime. (CORRECT)

You got it! We use the import command to import any module located in the PATH directory. We can also use import as to assign a localName variable to the imported module.

9. Which of the following is NOT an example of code completion?

  • After you type the letters “ret”, your IDE finishes your sentence with return.
  • After typing the opening parentheses after a function, your IDE inputs the final parentheses.
  • After typing “def”, your IDE detects that you are typing a function and highlights it. (CORRECT)
  • After typing the first few letters of an existing variable, your IDE suggests that variable, highlighting the suggestion.

Excellent! Syntax highlighting detects the language we’re writing our code in and highlights the pieces of code that make up the syntax of the language.

PRACTICE QUIZ: AUTOMATION

1. 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?

  • 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
  • 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 (CORRECT)
  • Provide a tablet computer to the employee to record uptime and downtime

Way to go! This is a practical application of using Python (and some extra hardware, in this case) to automate a task, freeing up a human’s time. The solutions can be complex if the return in saved human time warrants it.

2. 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 organize logs in a way that makes debugging easier. (CORRECT)
  • It’s important to remember that 20% of our tasks as system administrators is responsible for 80% of our total workload.
  • It’s important to have staff trained on how automation processes work so they can be maintained and fixed when they fail.

Right on! Forensic value, in relation to automation, is the value we get while debugging from properly logging every action our automation scripts take.

3. 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 their other duties. Assume that one month is four weeks, and it will take him 10 hours to code the automation script. Using the formula [time_to_automate < (time_to_perform * amount_of_times_done)], how long would it take them in minutes before they save time on the process?

  • 100 minutes (CORRECT)
  • 50 minutes
  • 40 minutes
  • 1 minute

Awesome! It would take the employee 100 minutes before they save time on the process.

4. 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?

  • 24 weeks
  • 2 weeks
  • 6 weeks
  • 240 weeks (CORRECT)

Right on! It’s safe to say that the company won’t find it worth it’s time to automate.

5. Which of the following are valid methods to prevent silent automation errors? (Check all that apply)

  • Regular consistency checks (CORRECT)
  • Internal issue tracker entries (CORRECT)
  • Email notifications about errors (CORRECT)
  • Constant human oversight

Awesome! Automated consistency checks, such as hash checks on backups, can help identify problems ahead of time.

Nice work! Internal issue tracker entries are created as part of reporting on errors in our automation script in this lesson.

Excellent! Email notifications for errors or task completions can help keep track of automated processes.

6. In terms of automation, which of the following is an example of scalability?

  • You fix an error in a script and it’s fixed there, once and forever.
  • An IT engineer writes a script to compile a report on each machine’s uptime and downtime for the day and email it to relevant parties every evening. (CORRECT)
  • A company hires more IT staff to keep up with work levels.
  • Minimizing workloads to stay within current productivity levels

Nice job! Scalability means that when more work is added to a system, the system can do whatever it needs to complete the work.

7. Which of the following correctly describes the Pareto Principle?

  • If we estimate that it’d take less time to automate the task than to do it manually, chances are it’s a good candidate for automation.
  • Four fifths of the sysadmin tasks you perform comprise one fifth of your total workload.
  • One fifth of the sysadmin tasks you perform comprise four fifths of your total workload. (CORRECT)
  • Is the time and effort it takes to write the script worth the potential automation benefits?

Awesome! The Pareto Principle states that 20% of the system administration tasks you perform are responsible for 80% of your workload. Therefore, identifying and automating those tasks will put your productivity through the roof!

8. Which of the following could be a good example of when to use an automation script?

  • Detect dangerously high CPU usage levels across a network and scale back the CPU clock speeds of those devices, or shut them down to prevent overheating (CORRECT)
  • Automate a process that will take longer to implement than it takes to do manually
  • Automate a process you might never use again
  • Automate a five-minute process that occurs once every six months

Awesome! These days most consumer devices do this on their own, but in the case of custom hardware or other specific use cases such as cluster networks, automation would fit this task nicely and reduce failover.

MODULE 1 GRADED ASSESSMENT

1. Which of the following statements most accurately defines automation? Select all that apply.

  • The process of streamlining workflows and making operations more efficient. (CORRECT)
  • Tasks that have been done manually previously that can be done at a faster rate.
  • The implementation of computer-controlled systems to manage and execute processes. (CORRECT)
  • The use of software or technology to perform tasks that would otherwise be done manually. (CORRECT)

Correct

2. Which of the following is an open source operating system?

  • Linux OS (CORRECT)
  • Apple
  • Windows OS
  • Mac OS

Correct

3. You run the command python –version and see the output Python 3.9.9. Which version of Python is your computer running?

  • Python 2
  • Python
  • Python 3 (CORRECT)
  • Python Unlimited

Correct

4. Which of the following best describes a compiled language?

  • A programming language that is converted into machine code before execution. (CORRECT)
  • A programming language that is typically slower than interpreted languages.
  • A programming language that is executed line by line by an interpreter.
  • A programming language that is typically used for scripting and web development.

Correct

5. You are a software developer working on a new project to create a web application. You are using a popular IDE called PyCharm to write your code. PyCharm provides a variety of features to help you develop your code, including a code editor, a debugger, and a terminal. Which of the following statements best describes the purpose of an IDE?

  • An IDE is a tool that helps software developers test their code for bugs.
  • An IDE is a tool that helps software developers write, debug, and test their code. (CORRECT)
  • An IDE is a tool that helps software developers deploy their code to production.
  • An IDE is a tool that helps software developers write their code more quickly and efficiently.

Correct

6. You are a site reliability engineer (SRE) responsible for maintaining the production environment for a popular web application. The application is built using a variety of Python frameworks and libraries, and new features are being added regularly. You are finding it increasingly difficult to manage the dependencies for the application. New releases of libraries can introduce breaking changes, and it can be challenging to keep track of which versions of each library are compatible with each other. You have heard about virtual environments, and you are wondering if they might be a solution to your problem. Which of the following statements best describes how virtual environments can help you solve your problem?

  • Virtual environments allow you to debug your code more efficiently.
  • Virtual environments allow you to install libraries in a way that is isolated from your system Python environment. (CORRECT)
  • Virtual environments allow you to test different versions of Python on your system.
  • Virtual environments allow you to deploy your code to production more easily.

Correct

7. You work for a growing company that just hired a large number of employees. To efficiently onboard a large number of new employees within a short timeframe. Previously the company had onboarded new hires manually. This is not possible anymore. What is the solution to this problem?

  • Develop a software application or utilize existing automation tools to automate the creation of user accounts, mailboxes, and home folders (CORRECT)
  • Utilize virtual machines so that several employees can import their information at once.
  • Hire another person to help onboard these new employees.
  • Create a centralized repository or knowledge base containing all necessary onboarding information, including company policies, procedures, and training materials.

Correct

8. According to the Pareto Principle, what percentage of system administration tasks typically account for 80% of the workload?

  • 80%
  • 10%
  • 20% (CORRECT)
  • 50%

Correct

9. A company uses a script to automatically generate reports from their customer relationship management (CRM) system. The script extracts data from the CRM system, formats the data into a report, and saves the report to a file. Which of the following statements best describes the purpose of the script? Select all that apply.

  • To save time and effort by automating the process of generating reports. (CORRECT)
  • To improve the accuracy and consistency of reports. (CORRECT)
  • To make it easier for users to access and analyze data from the CRM system. (CORRECT)
  • To increase security of the reports stored in the system. 

Correct

10. A banking company is looking to automate one of its internal processes that takes about 50 minutes each week to complete. The automation process will take 12 hours total to complete. How many weeks will it be before the banking company begins to save time on the process?

  • 600 days
  • 15 weeks
  • 50 weeks 
  • 12 WEEKS (CORRECT)

Correct

11. Which operating system can you use Python on? Select all that apply.

  • Linux OS (CORRECT)
  • Windows OS (CORRECT)
  • Mac OS (CORRECT)
  • Dell OS (CORRECT)

Correct

12. You are a software developer working on a new project to create a web application. You want to be able to develop your code in one place. You know you will need a code editor, debugger, and terminal. What should you use to create this application?

  • A Linux virtual machine
  • An operating system
  • An IDE (CORRECT)
  • A Text Editor

Correct

13. You are a busy marketing manager at a fast-paced startup company. You are constantly sending out emails to promote your company’s products and services. However, you are finding that this task is taking up a lot of your time. What could you implement to save time on this task?

  • Virtual Environments
  • Java
  • Email templates
  • Automation (CORRECT)

Correct

14. Which of the following factors would suggest that a task is a good candidate for automation? Select all that apply.

  • The task is repetitive and time consuming.
  • The task is error prone and difficult to complete manually. (CORRECT)
  • The task is done quickly.
  • The task must be performed once a year.

Correct

15. You are writing a python script and need to be able to copy, delete, move, and list files and directories? Which Python module should you use?

  • psutil
  • matplotlib
  • shutil (CORRECT)
  • pandas

Correct

16. What are the two main parts of an operating system?

  • core and system resources
  • kernel and user space (CORRECT)
  • system and user space
  • hard drive and kernel

Correct

17. You are a software developer working on a new project to create a web application. You are using a popular IDE called PyCharm to write your code. PyCharm provides a variety of features to help you develop your code, including a code editor, a debugger, and a terminal. Which of the following statements best describes the purpose of an IDE?

  • An IDE is a tool that helps software developers deploy their code to production.
  • An IDE is a tool that helps software developers write, debug, and test their code. (CORRECT)
  • An IDE is a tool that helps software developers write their code more quickly and efficiently.
  • An IDE is a tool that helps software developers test their code for bugs.

Correct

18. You are an IT automation engineer working on an automation script. You are using a variety of Python libraries in your script. You are also using a variety of different versions of these libraries. You are working on a team with other engineers, and you are finding it difficult to manage the different versions of Python libraries that everyone is using. You are worried that this will lead to conflicts and errors when you try to run your code. You have heard about virtual environments, and you are wondering if they might be a solution to your problem. Which of the following statements best describes how virtual environments can help you solve your problem?

  • Virtual environments allow you to test different versions of Python on your system.
  • Virtual environments allow you to debug your code more efficiently.
  • Virtual environments allow you to install libraries in a way that is isolated from your system Python environment. (CORRECT)
  • Virtual environments allow you to deploy your code to production more easily.

Correct

19. A company hires a lot of employees over a short period of time. Previously, the company completed onboarding tasks such as creating a user account, a mailbox, and a home folder, and setting up the appropriate permissions to control access to various systems and resources for each new employee manually. Because of this increase in new hires it would take a lot of time to onboard all of these new employees. What is the solution to this problem?

  • Java
  • Virtual Environments
  • Onboarding templates
  • Automation (CORRECT)

Correct

20. You want to create a Python script that automates system monitoring tasks on your computer. What Python module should you use in your script?

  • pandas
  • psutil (CORRECT)
  • numpy
  • matplotlib

Correct

21. What are some of the common Linux distributions? Select all that apply.

  • Red Hat (CORRECT)
  • Kernel
  • Debian (CORRECT)
  • Ubuntu (CORRECT)

Correct

22. What command should you type into your computer’s terminal to check which Python version is installed?

  • python installed — version
  • py check — version
  • py verify — version
  • python –version (CORRECT)

Correct

23. Which of the following statements accurately describes the difference between compiled and interpreted languages?

  • Compiled languages are typically faster than interpreted languages, while interpreted languages are more flexible and easier to develop. (CORRECT)
  • Interpreted languages are faster than compiled languages and are less prone to errors.
  • Interpreted languages are typically used for system programming, while compiled languages are typically used for scripting and web development.
  • Interpreted languages are converted into machine code before execution, while compiled languages are executed line by line by an interpreter.

Correct

24. Which formula would you use to determine if a task would save labor time and should be automated?

  • time_to_perform < (time_to_automate * amount_of_times_done) amount_of_times_done < (time_to_automate * time_to_perform) time_to_automate > (time_to_perform * amount_of_times_done)
  • time_to_automate < (time_to_perform * amount_of_times_done) (CORRECT)

Correct

CONCLUSION – Getting your Python on

To sum up, this module has provided a comprehensive exploration of operating systems, guiding you through the process of preparing your Python code for seamless interaction with diverse operating systems. The emphasis on environment configuration and the installation of additional Python modules has been pivotal in enhancing overall functionality. The distinctions between interpreted and compiled languages have been thoroughly examined, offering a clear understanding of their differences.

The module has also shed light on the advantages of automation, while also cautioning against common pitfalls. Finally, the introduction of Qwiklabs as a platform for graded assessments adds a practical and hands-on dimension to reinforce the learning experience. Armed with this knowledge, you are well-equipped to navigate the intricacies of operating systems and leverage Python effectively in your coding endeavors.