[go: up one dir, main page]

0% found this document useful (0 votes)
5 views12 pages

Module 1

Uploaded by

ASLAHA AL SERIN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Module 1

Uploaded by

ASLAHA AL SERIN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

MODULE 1

PROGRAMING
SYNTAX: The rules for how each instructions is written
SEMANTICS: The effects the instructions have
SCRIPT: Programs with short developmental cycle that can be created and deployed rapidly .In
other words, a script is a program that is short, simple, and can be written very quickly.

Uses for Automation


Scripts can be used for automating specific tasks. Automation is used to replace a repetitive
manual step with one that happens automatically. Humans are fallible. They can become tired,
make mistakes, fail to follow instructions, be inconsistent in their job performance, and more. In
contrast, automated processes complete instructions exactly as coded, in a consistent manner.
They can run 24 hours a day, everyday, without tiring. For many tasks that are appropriate for
automation, it can be more cost effective to use automation than human labor.

Appropriate uses for automation include:


The automatic timing and regulation of traffic lights
A repetitive task that is at high risk for human error
Sending commands to a computer
Detecting and removing duplicates of data
Sending automated emails that are personalized by pulling individual names from a database
and plugging them into the email
Updating a large number of file permissions
Reporting on system data, like disk or memory usage
Installing software
Generating reports
Deploying a file or a computer program to all computers on a company network
Using a configuration management system to deploy software patches, after a human has
designed the system
Populating an e-commerce site with products
Setting the home directory and access permissions for users
Automation is not always an appropriate or complete solution
Automation cannot perform all human work. Tasks that call for human creativity, social
connection, psychology, flexibility, ingenuity, evaluation, and/or complex analytic work are not
good candidates for full automation. Sometimes automation can be used to perform one or
more subtasks of a larger set of tasks – but – human intervention is required to complete the
tasks. The following are some examples of tasks that cannot or should not be fully automated:

Items that require human evaluation and analytic skills:


Designing a configuration management system
Investigating and troubleshooting all end user problems
Writing a computer program
Building a new startup business
Items that require human creativity and/or an eye for aesthetic qualities:
Designing an attractive webpage (AI can do this, but simple automation cannot)
Wedding photography
Haircuts and styling

Items that cannot be automated due to basic physics:


Troubleshooting or repairing machines that cannot power on or boot up
Items that need human interaction, psychology, and/or evaluation skills:
Interviewing and hiring new employees
Customer service (chat bots cannot address every customer service need)
Items that should not be fully automated due to costs and safety:
Grocery store checkout process, including bagging groceries
Tasks that are less expensive to perform manually

Artificial Intelligence
It is important to understand that basic automation is not the same as artificial intelligence.
Automation is used to explicitly instruct a machine on how to perform a task. Artificial
intelligence (AI) involves training a computing machine to perform more complex tasks through
a process called machine learning. This process prepares the AI software to perform new tasks
without a human needing to program explicit instructions for each task. Although AI is often
used for automating human tasks, AI automation is much more complex than basic automation.
Programming code - Programming code is a set of written computer instructions, guided by
rules, using a computer programming language. It might help to think of the computer
instructions as a detailed, step-by-step recipe for performing tasks. The instructions tell
computers and machines how to perform an action. Programming code may also be referred to
as source code or scripts.
Programming languages - Programming languages are similar to human spoken languages in
that they both use syntax and semantics. Programming languages are used to write computer
programs. Some common programming languages include Python, Java, C, C++, C#, and R.
Syntax - Syntax is a set of rules for how statements are constructed in both human and
computer languages. Programming syntax includes rules for the order of elements in
programming instructions, as well as the use of special characters and their placements in
statements. This concept is similar to the syntax rules for grammar and punctuation in human
language.
Semantics - Semantics refers to the intended meaning or effect of statements, or collections of
words, in both human and computer languages. Semantic errors are also referred to as logical
errors.
Computer program - A computer program is a step-by-step list of instructions that a computer
follows to reach an intended goal. It is important to be clear and precise about the actions a
computer program is supposed to perform because computers will do exactly what they are
instructed to do. Computer programs can be long, complex, and accomplish a variety of tasks.
They are often developed by computer programmers and software engineers, but anyone can
learn to create them. Computer programs may involve a structured development cycle. They
can be written in a wide variety of programming languages, such as Python, Java, C++, R, and
more. The completed format of a program is often a single executable file.
Script - Scripts are usually shorter and less complex than computer programs. Scripts are often
used to automate specific tasks. However, they can be used for complex tasks if needed.
Scripts are often written by IT professionals, but anyone can learn to write scripts. Scripts have
a shorter, less structured development cycle as compared to the development of complex
computer programs and software. Scripts can be written in a variety of programming
languages, like Python, Javascript, Ruby, Bash, and more. Some scripting languages are
interpreted languages and are only compatible with certain platforms.
Automation - Automation is used to replace a repetitive manual step with one that happens
automatically.
Output - Output is the end result of a task performed by a function or computer program.
Output can include a single value, a report, entries into a database, and more.
Input - Input is information that is provided to a program by the end user. Input can be text,
voice, images, biometrics, and more.
Functions - A function is a reusable block of code that performs a specific task.
Variables - Variables are used to temporarily store changeable values in programming code.
A Note on Syntax and Code Blocks
When writing code, using correct syntax is critical. Even a small typo, like a missing parenthesis
bracket or an extra comma, can cause a syntax error and the code won't execute at all. If your
code results in an error or an exception, pay close attention to syntax and watch out for minor
mistakes. A single wrong character could take hours to identify in long code so it is important to
be mindful of syntax when writing code.
Common syntax errors:
 Misspellings
 Incorrect indentations
 Missing or incorrect key characters:
 Bracket types - ( curved ), [ square ], { curly }
 Quote types - "straight-double" or 'straight-single', “curly-double” or ‘curly-single’
 Block introduction characters, like colons - :
 Data type mismatches
 Missing, incorrectly used, or misplaced Python reserved words
 Using the wrong case (uppercase/lowercase) - Python is a case-sensitive language
If your syntax is correct, but the script has unexpected behavior or output, this may be due to a
semantic problem. Syntax is like the vocabulary, grammar, spelling, and punctuation of code.
Semantics are the meaning and logic of coded statements. It is possible to have syntactically
correct code that runs successfully, but doesn't do what we want it to do.
Common semantic errors:
 Creating functional code, but getting unintentional output
 Poor logic structures in the design of the code
When working with the code blocks in exercises for this course, be mindful of syntax and
semantic (logic) errors, along with the overall result of your code. Just because you fixed an
error doesn't mean that the code will have the desired effect when it runs! Once you’ve fixed an
error in your code, don't forget to click Run to check your work.

Python is a general purpose programming language that is commonly used for scripting and
automation, as well as to develop a wide variety of applications. Python is compatible with most
operating systems, including Windows, Linux, and Mac OS, and is updated every few years.
Python can also run on a variety of machines, such as servers, workstations, PCs, mobile
devices, IoT, and more.Python is widely used in the IT field, including IT support, system
administration, web development, machine learning, data analytics, and more. Python can be
used to calculate statistics, run your e-commerce site, process images, interact with web
services, and do a whole host of other tasks. Python instructions resemble the English
language, which is what makes it easier to learn and understand when compared to other
programming languages.
Python is:
 a general purpose scripting language;
 a popular language used to code a variety of applications;
 a frequently used tool for automation;
 a cross-platform compatible language;
 a beginner-friendly language.
Python is not:
 A platform-specific / OS-specific scripting language;
 a client-side scripting language;
 a purely object-oriented programming language
Code comparison with Python
You will be learning about both Python and Bash scripting in this program. The following code
illustrates a syntax difference between the two languages:

Print to screen in Python


>> print("Hello, how are you?")
Hello, how are you?
Print to screen in Bash
>> echo Hello, how are you?
Hello, how are you?

Key Terms
 Platform-specific / OS specific scripting language - Platform-specific scripting
languages, like PowerShell (for Windows) and Bash (for Linux), are used by system
administrators on those platforms.
 Client-side scripting language - Client-side scripting languages, like JavaScript, are used
mostly for web programming. The scripts are transferred from a web server to the end-
user’s internet browser, then executed in the browser.
 Machine language - Machine language is the lowest-level computer language. It
communicates directly with computing machines in binary code (ones and zeros). In binary
code, one equals a pulse of electricity and zero equals no electrical pulse. Machine
language instructions are made from translating languages like Python into complex
patterns of ones and zeros.
 Cross-platform language - Programming language that is compatible with one or more
platforms / operating systems (e.g., Windows, Linux, Mac, iOS, Android).
 Object-oriented programming language - In object-oriented programming languages, most
coding elements are considered to be objects with configurable properties. For example, a
form field is an object that can be configured to accept only dates as input in the mm/dd/yy
format, and can be configured to read from and write to a specific database.
 Python interpreter - An interpreter is the program that reads and executes Python code by
translating Python code into computer instructions.
Functions
A function is a piece of code that performs a unit of work. In the examples you've seen so far,
you have only encountered the print() function, which outputs a message to the screen. You will
use this function frequently in this course to check the results of your code. The syntax of the
print() function is modeled in the example below.
123# Syntax for printing a string of text. Click Run to check the result. print("Hello world!")
# Syntax for printing a string of text. Click Run to check the result.
print("Hello world!")
Hello world!
Keywords
A keyword is a reserved word in a programming language that performs a specific purpose. In
your first Python example, you briefly encountered the keywords for and in. Note that keywords
will often appear in bold in this course.
Values: True, False, None
Conditions: if, elif, else
Logical operators: and, or, not
Loops: for, in, while, break, continue
Functions: def, return
Arithmetic operators
Python can calculate numbers using common mathematical operators, along with some special
operators, too:
x+y Addition + operator returns the sum of x plus y
x-y Subtraction - operator returns the difference of x minus y
x*y Multiplication * operator returns the product of x times y
x/y Division / operator returns the quotient of x divided by y
x**y Exponent ** operator returns the result of raising x to the power of y
x**2 Square expression returns x squared
x**3 Cube expression returns x cubed
x**(1/2) Square root (½) or (0.5) fractional exponent operator returns the square root of x
x // y Floor division operator returns the integer part of the integer division of x by y
x%y Modulo operator returns the remainder part of the integer division of x by y

Order of operations
The order of operations are to be calculated from left to right in the following order:
 Parentheses ( ), { }, [ ]
 Exponents xy (x**y)
 Multiplication * and Division /
 Addition + and Subtraction -
You might find the PEMDAS mnemonic device to be helpful in remembering the order.
PyCharm
PyCharm is a very popular IDE for Python development. It is an open source IDE that offers
many great features to help you write better code faster. It is an intelligent code editor that has
useful features, including code completion, error detection, and on-the-fly code fixes. PyCharm
also allows you to navigate easily through your code with code folding, code search, and code
structure diagrams. The built-in debugger provides breakpoints, step-by-step execution, and
variable inspection which allows you to find and fix bugs very quickly. You can test your code
within the IDE which allows you to ensure your code is reliable and error free. Finally, PyCharm
also offers a wide range of plug-ins created by its community of developers which has
expanded its functionality.

Overall, PyCharm is a great choice when it comes to an IDE. It is great for beginners because it
is easy to use and has a large community of users which means there are tons of tutorials and
resources available online. PyCharm is also highly customizable. It is a popular IDE that many
developers use and love!
PyDev
PyDev is an open source IDE for Python Development that is based on Eclipse. PyDev
includes an intelligent code editor, code navigation, debugging, testing, and refactoring. Its
refactoring engine can help you improve the structure and readability of your code which makes
maintenance and debugging easier. PyDev is also fully integrated with Eclipse which means
you can use all of Eclipse’s features like project explorer, the perspective system, and its built-in
debugger. PyDev is a great IDE for developers at any stage! It's free to use, compatible with
many versions of Python, and its plugins make it extensible. PyDev has a large community of
users and developers which means there are lots of tutorials, resources, and forums online.
Notepad++
Notepad++ is an open source text editor for Microsoft Windows environments. It supports many
programming languages, including Python. Notepad++ can open multiple files and tabs. It also
does syntax highlighting for known file types. Syntax highlighting helps you edit code because it
displays text in different colors and fonts that help you keep track of the classes, methods,
functions, and objects in your code. It also helps you identify errors in your code so you can
spend less time debugging. Notepad++ has a number of other advanced features, like auto-
completion and file management systems that can help you code more efficiently. Notepad++ is
a great text editor for developers who work in a Microsoft Windows environment! It has an
active, collaborative community. Users can ask the community for help and even contribute to
the project!
Terms and definitions from Course 1, Module 1
Automation: The process of replacing a manual step with one that happens automatically
Client-side scripting language: Primarily for web programming; the scripts are transferred
from a web server to the end-user’s internet browser, then executed in the browser
Code editors: Tools to provide features, including syntax highlighting, automatic indentation,
error checking, and autocompletion
Computer program: A step-by-step list of instructions that a computer follows to reach an
intended goal
Functions: A reusable block of code that performs a specific task
IDE: A software application that provides comprehensive facilities for software development
Interpreter: The program that reads and executes code
Input: Information that is provided to a program by the end user
Logic errors: Errors in code that prevent it from running correctly
Machine language: Lowest-level computer language. It communicates directly with computing
machines in binary code (ones and zeros)
Object-oriented programming language: Most coding elements are considered to be objects
with configurable properties
Output: the end result of a task performed by a function or computer program
Platform-specific scripting language: Language used by system administrators on those
specific platforms
Programming: The process of writing a program to behave in different ways
Programming code: A set of written computer instructions, guided by rules, using a computer
programming language
Programming languages: Language with syntax and semantics to write computer programs
Python: A general purpose programming language
Python interpreter: Program that reads and executes Python code by translating Python code
into computer instructions
Script: Often used to automate specific tasks
Semantics: The intended meaning or effect of statements, or collections of words, in both
human and computer languages
Syntax: The rules for how each statements are constructed in both human and computer
languages
Variables: These are used to temporarily store changeable values in programming code

Annotating variables by type


Type annotation allows you to clearly communicate the argument types and return type of
functions in your code. It’s like giving yourself and other developers hints about what kind of
data the variable is supposed to hold. This has several benefits: It reduces the chance of
common mistakes, helps in documenting your code for others to reuse, and allows integrated
development software (IDEs) and other tools to give you better feedback. In this reading, you
will learn more about annotating variables by type and best practices.
How to annotate a variable
Think of annotating a variable as if you were to put a label on a container—and anything in that
container should hold what the label is describing. Let’s take a look at an example:
name: str = “Betty”
The variable name is declared using a colon (:) which is annotated with the type str, indicating
that the name variable should hold a string value. And look, it does! Betty—or any name for that
matter—is a string, and we know it’s a string because it is in quotes. Let’s look at another
example where a variable holds an integer value.
age: int = 34
In this example, age is the variable, and int is the type annotation that provides you and other
developers a hint that the age variable should store an integer value.
Pro tip: If a function expects a list of integers, you should annotate it as List[int], not just List.
Being specific with your types can catch more potential bugs and misunderstandings.
Dynamic typing
Many languages, such as C# or Java, require you to declare variable types, but not Python.
One of the great things about Python is that the type of variable can change over time as new
values are assigned to it. For example:
a=3 #a is an integer
a = “Hello world” #a is now a string
Dynamic typing allows programmers to write code more quickly and offers flexibility because
you don’t have to explicitly declare the type of variable.
Note: Python decides which of the built-in types the variable is and, therefore, how it should
behave. For more information, refer to this article on Built-in types.
Duck typing
This form of typing comes from the saying, “If it walks like a duck and quacks like a duck, it
must be a duck.” Python will infer the variable type at runtime and decide which behaviors are
available to the given object.
a = “Hello world” #looks like a string
Annotating variables with type comments
Another way to annotate variables is to use type comments where the interpreter will ignore the
comments.
captain = “Picard” # type: str
Note: This way of annotating variables might be useful for cases when you need to know what
types belong to which variables but do not want the overhead of using a line interpreter (linter)
or IDE on this specific variable.
Annotating variables directly
Let’s use the same example above to annotate a variable directly.
captain: str = “Picard”
Note: You might hear annotating variables directly called the more “modern” way to annotate a
variable.
Another advantage is that you can use automated tools such as linters, or mypy, to check types
to make code more resilient. Most modern IDEs, such as VS Code and JetBrains PyCharm,
scan code for type annotations and can use it to help you write better code more quickly!
How type annotations affect runtime behavior
Any time a library is called, or an IDE works to scan your code, more computational overhead is
required.
Pro tip: Be strategic when annotating variables by type. This can add unnecessary overhead
when overused.
Type annotation is less common with Python users in data science, as it can be burdensome to
manually map data every time a new set of data comes in. On the other hand, when doing
object-oriented programming or writing functions, using type annotations becomes extremely
important because it helps clarify code since you are dealing with more than just the built-in
types.
Key takeaways
Annotating variables by type provides programmers with benefits to make the code easier to
read and understand. Python provides different options on how to annotate variables, so
choose how you want to annotate them. Just be cautious of over-annotating, creating
unnecessary overhead to your code.
Expressions and variables
This study guide provides a quick-reference summary of what you learned in this lesson and
serves as a guide for the upcoming practice quiz.
In the Expressions and Variables segment, you learned about expressions, variables, and the
data types: string, integer, and float. You learned how to convert a value from one data type to
another and you learned how to resolve a few common errors in Python.
Terms
 expression - a combination of numbers, symbols, or other values that produce a result
when evaluated
 data types - classes of data (e.g., string, int, float, Boolean, etc.), which include the
properties and behaviors of instances of the data type (variables)
 variable - an instance of a data type class, represented by a unique name within the
code, that stores changeable values of the specific data type
 implicit conversion - when the Python interpreter automatically converts one data type
to another
 explicit conversion - when code is written to manually convert one data type to
another using a data type conversion function:
o str() - converts a value (often numeric) to a string data type
o int() - converts a value (usually a float) to an integer data type
o float() - converts a value (usually an integer) to a float data type
 return value - the value or variable returned as the end result of a function
 parameter (argument) - a value passed into a function for use within the function
 refactoring code - a process to restructure code without changing functionality
Knowledge
 The purpose of the def() keyword is to define a new function.
 Best practices for writing code that is readable and reusable:
o Create a reusable function - Replace duplicate code with one reusable
function to make the code easier to read and repurpose.
o Refactor code - Update code so that it is self-documenting and the intent of the
code is clear.
o Add comments - Adding comments is part of creating self-documenting code.
Using comments allows you to leave notes to yourself and/or other
programmers to make the purpose of the code clear.

Built-in functions: Functions that exist within Python and can be called directly
Comments: Notes to yourself and/or other programmers to make the purpose of the code clear
Data types: Classes of data (e.g., string, int, float, Boolean, etc.), which include the properties
and behaviors of instances of the data type (variables)
Explicit conversion: This occurs when code is written to manually convert one data type to
another using a data type conversion function
Expression: A combination of numbers, symbols, or other values that produce a result when
evaluated
Implicit conversion: This occurs when the Python interpreter automatically converts one data
type to another
Logical operators: Operators used to combine or manipulate boolean values (True or False)
to create complex conditions for decision-making.
Parameter (argument): A value passed into a function for use within the function, controlling
the behavior of the CSV reader and writer
Refactoring: When a code is updated to be more self-documenting and clarify the intent
Return value: This is the value or variable returned as the end result of a function

You might also like