Course 1 – CRASH COURSE ON PYTHON

Module 1: Hello Python!

GOOGLE IT AUTOMATION WITH PYTHON PROFESSIONAL CERTIFICATE

Complete Coursera Study Guide

Last updated:

INTRODUCTION – Hello Python!

In this module, the primary focus is to acquaint you with the Coursera platform and familiarize you with the course format. Once the stage is set, you will embark on a journey into the fundamentals of programming languages and syntax, delving into the realm of automation through scripting. The spotlight of this module is on introducing you to the Python programming language, where we will cover essential functions, keywords, and delve into basic arithmetic operations within the language.

As we navigate through the intricacies of Python, you’ll gain a foundational understanding of its core elements. We’ll unravel the basics, allowing you to grasp fundamental functions and keywords that form the building blocks of Python programming. Additionally, this module will equip you with insights into arithmetic operations, providing a solid groundwork for more advanced concepts.

Towards the conclusion of the module, the course will broaden your horizons by introducing various code editors and Integrated Development Environments (IDEs). These tools are pivotal in facilitating the writing of Python code efficiently and will empower you to choose the most suitable environment for your programming endeavors.

Learning Objectives

  • Define the terms computer program, programming language, script, and automation
  • Use the print() function to output data to the screen
  • Explain the difference between the syntax and semantics of a programming language
  • List some of the characteristics of the Python language
  • Utilize basic Python arithmetic operators to obtain the results of mathematical expressions

PRACTICE QUIZ: INTRODUCTION TO PROGRAMMING

1. What’s a computer program?

  • A set of languages available in the computer
  • A process for getting duplicate values removed from a list
  • A list of instructions that the computer has to follow to reach a goal (CORRECT)
  • A file that gets copied to all machines in the network

You nailed it! At a basic level, a computer program is a recipe of instructions that tells your computer what to do.

2. What’s the syntax of a language?

  • The rules of how to express things in that language (CORRECT)
  • The subject of a sentence
  • The difference between one language and another
  • The meaning of the words

Right on! In a human language, syntax is the rules for how a sentence is constructed, and in a programming language, syntax is the rules for how each instruction is written.

3. What’s the difference between a program and a script?

  • There’s not much difference, but scripts are usually simpler and shorter. (CORRECT)
  • Scripts are only written in Python.
  • Scripts can only be used for simple tasks.
  • Programs are written by software engineers; scripts are written by system administrators.

You got it! The line between a program and a script is blurry; scripts usually have a shorter development cycle. This means that scripts are shorter, simpler, and can be written very quickly.

4. Which of these scenarios are good candidates for automation? Select all that apply.

  • Generating a sales report, split by region and product type (CORRECT)
  • Creating your own startup company
  • Helping a user who’s having network troubles
  • Copying a file to all computers in a company (CORRECT)
  • Interviewing a candidate for a job
  • Investigating the root cause of a machine failing to boot

Excellent! Creating a report that presents stored data in specific ways is a tedious task that can be easily automated.

Nice work! A task like copying files to other computers is easily automated, and helps to reduce unnecessary manual work.

5. What are semantics when applied to programming code?

  • The rules for how a programming instruction is written
  • The difference in number values in one instance of a script compared to another
  • The intended meaning or logic of coded statements (CORRECT)
  • The end result of a programming instruction

Nice job! The intended meaning or effect of coded statements are referred to as semantics. 

6. Why do we need to learn the syntax and semantics of a programming language?

  • To be able to easily switch to a different programming language
  • So that we know which part is the subject and which one is the predicate
  • To allow us to clearly express what we want the computer to do (CORRECT)
  • To understand why our computer crashes

You nailed it! Knowing the syntax and understanding the semantics of a programming language allows us to tell the computer what we want it to do.

7. What’s automation?

  • The process of telling a computer what to do
  • The process of installing traffic lights
  • The process of getting a haircut
  • The process of replacing a manual step with one that happens automatically (CORRECT)

Right on! By replacing a manual step with an automatic one we create automation that helps us reduce unnecessary manual work.

8. Which of the following tasks do you think are good candidates for automation? Check all that apply.

  • Investigating reports that customers are having difficulty accessing your company’s external website
  • Installing software on laptops given to new employees when they are hired (CORRECT)
  • Designing a configuration management system for deploying software patches
  • Periodically scanning the disk usage of a group of fileservers (CORRECT)

Right on! Installing and configuring software is a task that can be automated. Ensuring that everyone gets the exact same setup and reducing the amount of manual work needed for each new employee.

You nailed it! Scanning the disk usage is a task that can be easily automated. By letting the computer do it, you won’t have to worry about forgetting to do it whenever it’s needed.

PRACTICE QUIZ: INTRODUCTION TO PROGRAMMING

1. Python is an example of what type of programming language?

  • General purpose scripting language (CORRECT)
  • Machine language
  • Client-side scripting language
  • Platform-specific scripting language

You got it! Python is one of the general purpose scripting languages that are widely used for scripting and automation.

2. Why is Python relevant to IT? Select all that apply.

  • Python is used in fast-growing areas of IT, like machine learning and data analytics. (CORRECT)
  • Python works well as a scripting language for IT automation. (CORRECT)
  • Python scripts run on IT servers only.
  • Python can be used to calculate statistics, run e-commerce sites, process images, interact with web services, and more. (CORRECT)

Correct! Python is a popular tool used in the IT fields of machine learning and data analytics.

Correct! Python lets you automate repetitive IT tasks by writing simple scripts that are easy to understand and easy to maintain.

Correct! Python is very versatile and can be used for a wide variety of IT-related tasks.

3. Let’s check whether you soaked all that in with a quick question! Select all options that explain why Python is relevant to today’s IT industry.

  • Python scripts are easy to write, understand, and maintain. (CORRECT)
  • There are many system administration tools built with Python. (CORRECT)
  • Python was written by Guido van Rossum in 1991.
  • Python is available on a wide variety of platforms. (CORRECT)
  • There have been multiple major version releases over the years which incorporate significant changes to the language.

Woohoo! Python is a language that tries to mimic our natural language and so Python scripts are generally easy to write, understand and maintain.

You got it! Over the years, the Python community has developed a lot of additional tools that can be used by system administrators to get their job done.

Well done, you! Python is available on Windows, Linux, MacOS and even on mobile devices, making it a great tool for IT specialists looking to create scripts that can work across platforms.

PRACTICE QUIZ: HELLO WORLD

1. What are functions in Python?

  • Functions let us use Python as a calculator.
  • Functions are pieces of code that perform a unit of work. (CORRECT)
  • Functions are only used to print messages to the screen.
  • Functions are how we tell if our program is functioning or not.

Right on! Python functions encapsulate a certain action, like outputting a message to the screen in the case of print().

2. What are keywords in Python?

  • Keywords are reserved words that are used to construct instructions. (CORRECT)
  • Keywords are used to calculate mathematical operations.
  • Keywords are used to print messages like “Hello World!” to the screen.
  • Keywords are the words that we need to memorize to program in Python.

You got it! Using the reserved words provided by the language we can construct complex instructions that will make our scripts.

3. What does the print function do in Python?

  • The print function generates PDFs and sends it to the nearest printer.
  • The print function stores values provided by the user.
  • The print function outputs messages to the screen (CORRECT)
  • The print function calculates mathematical operations.

You nailed it! Using the print() we can generate output for the user of our programs.

MODULE 1 GRADED ASSESSMENT

1. What is a computer program?

  • The overview of what the computer will have to do to solve an automation problem.
  • Step-by-step instructions on how to complete a set of tasks, to be executed by a computer. (CORRECT)
  • The syntax and semantics of a programming language.
  • A file that gets printed by the Python interpreter.

2. What is a function?

  • A document describing a software project
  • A reusable block of code that performs a specific task (CORRECT)
  • The beginning of a program defining who wrote it and why
  • The task a program is written to accomplish

3. What are some of the benefits of automation? Select all that apply.

  • More cost-effective for complex, seldom-done tasks
  • Consistency (CORRECT)
  • Can accomplish creative tasks
  • Doesn’t get tired (CORRECT)

4. What is the term for the intended meaning or effect of statements in a programming language?

  • Semantics (CORRECT)
  • Format
  • Grammar
  • Syntax

5. What is a property of Python that makes it easier to understand than some other programming languages?

  • You can use Python code in any other language.
  • Python doesn’t have a defined syntax.
  • Code is similar to the English language. (CORRECT)
  • Basic guidelines can be given and it will write the code.

6. What should be the output of the expression below?

1	1 print((9-3)/(2*(1+2)))
  • 1.0 (CORRECT)
  • 19.36
  • 49.0
  • 0.28

7. What is automation?

  • The inputs and outputs of a program
  • The process of replacing a manual step with an automated step (CORRECT)
  • The rules of a programming language
  • The process of designing a solution to a problem

8. What is the difference between syntax and semantics in a programming language?

  • Syntax is a set of rules for how statements are constructed. Semantics refers to the intended meaning or effect of statements. (CORRECT)
  • Syntax is the effect the instructions have on the system and semantics are how to write the instructions.
  • Syntax is the tool that executes a computer program and semantics is the development environment.
  • Syntax refers to computer programs and semantics is another word for scripts.

9. What is the program that reads and executes Python code by translating it to computer instructions called?

  • Interpreter (CORRECT)
  • Compiler
  • Translator
  • Linker

10. Which Python function will output text, or other value, to the screen?

  • echo
  • print() (CORRECT)
  • output()
  • console.out

11. Once you have learned the basics of a programming language, how does this affect your ability to learn and use a second programming language?”

  • It’s difficult to learn and use a second language.
  • It’s easier to learn and use a second language. (CORRECT)
  • The syntax and semantics will be the same.
  • You should only code in one language.

12. What are some tasks that might be a good fit for full automation? Select all that apply.

  • Detecting and removing duplicate data (CORRECT)
  • Interviewing and hiring employees
  • Updating specific files on multiple computers (CORRECT)
  • Haircuts and styling

13. What should be the output of the expression below?

1	print(12/(1+2)+2**2)
  • 8.0 (CORRECT)
  • 6.0
  • 15.0
  • 81.0

14. Which of the following are true about programming languages? Select all that apply.

  • Similar to human language, programming languages use syntax and semantics. (CORRECT)
  • Programming languages are used to write computer programs and scripts. (CORRECT)
  • Programming languages is a synonym for pseudocode.
  • Some common programming languages include Python, Java, C, C++, C#, and R. (CORRECT)

15. Which of the following are characteristics of the Python language? Select all that apply.

  • Python is cross-platform compatible (CORRECT)
  • Python is used in a wide variety of applications (CORRECT)
  • Python has many platform-specific tools, like Bash or Powershell
  • Python is an object-oriented language not fit for general purpose scripting

16. Which Python function will output text, or other value, to the screen?

  • echo
  • print() (CORRECT)
  • output()
  • console.out

17. What should be the output of the expression below?

1	print(2+2/((2+2)+(2**2)))
  • 5.0
  • 50.0
  • 2.25 (CORRECT)
  • 12.0

18. Use the Python print function to calculate how many number-based passcodes can be formed with 10 numerals (0 through 9).  Here’s a hint to help you: When each digit of a passcode is independent of the others, the total number of combinations is simply the number of possibilities for each digit raised to the power of the length of the passcode. So, for a 1-numeral passcode, there would be 10 possibilities; one for every numeral from 0 to 9.  For a 2-numeral passcode, each numeral is independent of the other, so there would be 10 times 10 possibilities. Using this information, print the amount of possible passwords that can be formed with 3 numerals.

Note: Your result should be in the number format, not a sentence.

Use the Python print function to calculate - Question
Coursera img
1	# Should print 1000
2	print(10**3)

Correct!

19. Keeping in mind there are 60 seconds per minute, write a program that calculates how many seconds there are in an hour. Print the result to the screen. Note: Your result should be in the format of just a number, not a sentence.

60 seconds per minute - Question
Coursera img
1	# Enter code here:
2	print(60*60)
3	# Should print 3600

20. Fill in the blank to calculate how many sectors a given 16 GB (gigabyte) hard disk drive has. The given hard drive is divided into sectors of 512 bytes each. Divide the total bytes on the drive by the number of bytes in a sector to calculate how many sectors this drive has.  Your result should be a number. Note: To calculate the total bytes on the disk drive, multiply by multiples of 1024. In the code below,  you can calculate the “disk_size” of 16 GB by multiplying 16 by 1024 three times to go from bytes, to kilobytes, to megabytes, and finally to gigabytes.

calculate how many sectors a given 16 GB (gigabyte) - Question
Coursera img
1	disk_size = 16*1024*1024*1024
2	sector_size = 512
3	sector_amount = float(disk_size/sector_size)
4	
5	print(sector_amount) # Should print 33554432.0

21. The computer will find any loopholes it can.

  • If a program is not clear, it’s called a script.
  • Computers do exactly what they are told. (CORRECT)
  • A program won’t work if there are any logic errors.

22. Which of the following are characteristics of the Python language? Select all that apply.

  • Python is cross-platform compatible (CORRECT)
  • Python is used in a wide variety of applications (CORRECT)
  • Python has many platform-specific tools, like Bash or Powershell
  • Python is an object-oriented language not fit for general purpose scripting

23. Write a Python script that outputs “Automating with Python is fun!” to the screen. Remember that syntax precision is important in programming languages. A missing capital letter, spelling error, or punctuation mark can produce errors.

1	print("Automating with Python is fun!")

24. In one year, if there are 365 days, with 24 hours in a day, , write a program to calculate the number of hours in a year. Print the result on the screen. Note: Your result should be in the format of just a number, not a sentence.

In one year, if there are 365 days, with 24 hours in a day - Question
Coursera img
1	# Enter code here:
2	print(24*365)
3	
4	# Should print 8760

25. Use Python to calculate how many different passwords can be formed with 6 lower case English letters (excludes any character not found in the English alphabet).  For a 1 letter password, there would be 26 possibilities; one for every letter of the English alphabet.  For a 2 letter password, each letter is independent of the other, so there would be 26 times 26 possibilities. Using this information, print the amount of possible passwords that can be formed with 3 letters.

Use Python to calculate how many different passwords can be formed - Question
Coursera img
1	# Enter code here:
2	print(26**3)
3	
4	# Should print 17576

26. Assuming there are 60 minutes in an hour, write a program that calculates the number of minutes in a 24 hour day. Print the result on the screen. Note: Your result should be in the format of just a number, not a sentence.

Assuming there are 60 minutes in an hour - Question
Coursera img
1	# Enter code here:
2	print(24*60)
3	# Should print 1440

28. Consider this scenario about using Python to make calculations:

In a managed computing environment, there are 200 remote computers that must download 200 MB (megabytes) of updates each month. There are 1024 KB (kilobytes) in each MB.

Fill in the blank in the code below to compute the number of total kilobytes downloaded by all computers from the remote update server each month. Multiply the total number of computers by the download size in KB to calculate.

there are 200 remote computers that must download 200 MB (megabytes) of updates each month - Question
Coursera img
1	download_size_kb = 200*1024
2	total_computers = 200
3	total_kbs = float(download_size_kb*total_computers)
4	
5	print(total_kbs) # Should print 40960000.0

CONCLUSION – Hello Python!

In conclusion, this introductory module has laid the groundwork for your journey on the Coursera platform and within the course structure. We’ve navigated through the basics of programming languages and syntax, emphasizing the pivotal role of automation through scripting. The focal point of our exploration has been the introduction to the Python programming language, where we covered fundamental functions, keywords, and essential arithmetic operations.

As you embark on this learning path, you’ve gained a solid foundation in Python, a versatile language widely used in various domains. The comprehension of basic functions, keywords, and arithmetic operations positions you well for the upcoming modules, where we will delve deeper into the intricacies of programming and automation. Additionally, with insights into different code editors and IDEs, you are equipped to choose the tools that best suit your coding preferences.

Get ready to apply this newfound knowledge as we venture further into the world of programming and automation in the subsequent modules. The journey has just begun, and we look forward to seeing your skills evolve and flourish in the dynamic landscape of programming with Python.