0% found this document useful (0 votes)
3 views19 pages

Python Scripting for DevOps Basics

This document serves as an introduction to Python scripting, specifically for DevOps specialization, covering console input and output. It outlines learning objectives, installation instructions for Python and IDEs, and differences between Python versions. The document also includes lessons on writing programs, using the print and input functions, and a programming assignment for learners.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views19 pages

Python Scripting for DevOps Basics

This document serves as an introduction to Python scripting, specifically for DevOps specialization, covering console input and output. It outlines learning objectives, installation instructions for Python and IDEs, and differences between Python versions. The document also includes lessons on writing programs, using the print and input functions, and a programming assignment for learners.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Python Scripting

• 1st Course in Python Scripting for DevOps Specialization

© LearnQuest 2015
2021
Console Input and Output
In this module, we roll up our sleeves and start coding! We will
learn to use Python to gather input from the keyboard and
send output to the console.
1

2 © LearnQuest 2021
Learning Objectives
Console Input and Output

Upon completion of this module, learners will be able to:


• Develop programs that read user input from the keyboard

• Develop programs that output information to the console

• Compile and run Python Programs in Visual Studio Code (VSCode)

• Compile and run Python Programs from IDLE

3 © LearnQuest 2021
Lesson 1 In this lesson we look at how the
learner can download and install
Getting and Using Python the Python and the IDLE IDE

4 © LearnQuest 2021
What is Python?
Python is a programming language that lets you work quickly
and integrate systems more effectively.

• For this course we will be using Both VSCode and IDLE include
an Integrated Development • Syntax Highlighting
Environment (IDE) in the web • Code Completion
browser called VSCode. • Debugger
• You can also download Python • Execute Code with a Single Button
from [Link] and it will • Step through Code Line By Line
include IDLE as the default IDE. • Interrogate Variables while
executing

5 © LearnQuest 2021
How is Python
Different?

Python is designed to get


you programming faster
• No Need to Declare Variables
• Dynamic vs Static Typing
• Scripting vs Programming

6 © LearnQuest 2021
Python 2 versus 3
Python 3 is the
Python 2 is
latest major version
embedded in some
of Python and has
operating systems
been released for
as a scripting tool
over 10 years

Easy to convert
between two
versions
- Print vs. Print()
7 © LearnQuest 2021
How to Get Started Coding
• Python is installed by default on most Unix based Systems
• Linux – Most modern distros include Python 3
• macOS – Includes Python 2 – You can install Python 3 with xCode

• On Windows you can download from


• [Link] – IDLE is installed as the IDE
• [Link] – After start VSCode there is a button to install python

• All programming assignments in this class include VSCode in the browser


• You can play around – submit button to submit programming assignment

8 © LearnQuest 2021
Text Editor vs IDE
You can use any text editor or IDE to write the code in this course

Windows macOS Linux


• Visual Studio • TextEdit • Vim
Code • Visual Studio • Atom
• Notepad Code
• Notepad++
• Notepad2

9 © LearnQuest 2021
Lesson 1
Review Visual Studio Code is a Free IDE
from Microsoft

An IDE is an Integrated
Development Environment

A Text Editor stores your human


readable code without special
characters

10 © LearnQuest 2021
Lesson 2 In this lesson we look at how
to write a Python program that
Sending text to
sends text to the console
the Console

11 © LearnQuest 2021
Hello World in Visual Studio
File Extension needs to be .py

12 © LearnQuest 2021
Sending Text to Console
• The print function takes a string
parameter and send it to the console

• By default, print sends the cursor


to the next row

• Think of the console as an


80 column x 20 row output

• If you add a comma and override the


end character you can leave the
cursor at the end of the output
• print(‘Hello World’, end =‘’)

13 © LearnQuest 2021
Lesson 2
By default, the print function
Review sends the cursor to the next row
first column

You can pass an empty char to the


end parameter which will leave the
cursor at the end of the output

Python programs have an


extension of py

14 © LearnQuest 2021
Lesson 3 In this lesson we look at how
to gather input from the user
Reading text from from the keyboard
the Keyboard

15 © LearnQuest 2021
Reading Text from the Console Keyboard

The input function


We can use the
returns a string of
string returned in
text that was read
any expression
up to the enter key

16 © LearnQuest 2021
Formal Greeting Program
The following program asks the user their name and then greets them

17 © LearnQuest 2021
First Programming Assignment

Part 1 Write a program that says “Hello Coursera”

[Link] a program that reads in the users Name


Part 2 and says, “Welcome to Coursera [Name]”.
[Name should replace the input value]

18 © LearnQuest 2021
Lesson 3
Review Standard Input for our programs will
come from the keyboard as a string

The input function returns data


entered on the keyboard up to
the enter key

The input returned from the


input function can be used
anywhere that a string can be
used in the code

19 © LearnQuest 2021

You might also like