0% found this document useful (0 votes)
4 views7 pages

Alison Python and Linux Course

The document provides an introduction to Python programming, covering key concepts such as problem-solving principles, the use of variables, and basic syntax for displaying text. It also discusses advanced topics like loops, functions, error handling, and file management. Additionally, it includes a brief overview of Linux, emphasizing its open-source nature and command-line interface.
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)
4 views7 pages

Alison Python and Linux Course

The document provides an introduction to Python programming, covering key concepts such as problem-solving principles, the use of variables, and basic syntax for displaying text. It also discusses advanced topics like loops, functions, error handling, and file management. Additionally, it includes a brief overview of Linux, emphasizing its open-source nature and command-line interface.
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 PROGRAMMING

The key points from this module are:


1, The Basic principle of programming is that it is problem solving.
2, Python is one of the easier programming languages to learn, and many of
its tools are free to download and use.
3, One you learn how to code in one programming language it will be easier to
learn other programming languages, as the principles are the same.
4, There are a lot of different variations of Python, IronPython, Ipython,
CPython to name a few. Most of python�s variations only have some syntax
differences but not
too many.
5, Comments are very useful in your code to help you or someone else
understand:
- What your program does,
- What a particular line or section of code does;
- Why you chose to do something a particular way;
- Anything that might be helpful to know if you or someone else looking at
the code later and trying to understand it.
6, The # is the symbol to indicate using comments in python.

Module 2: Displaying Text


The key points from this module are:
1, One of the simplest but most important things you need that ability to do
in programming is display text.
2, For displaying text in Python you use the print() statement.
3, Your text inside prints brackets must be enclosed with quotes, Python
accepts both single � and double � quotes.
4, For printing on multiple lines you could use multiple print statements or
you can use \n which declares a new line for the text that follows it.
5, You can you triple quotes for the text to display, as you have typed it
into the editor this is not a recommended method as most other programming
languages
don�t support it.
6, You will make mistakes when programming all programmers make mistakes from
typing mistakes to logic mistakes, it is not something to stress over.
7, Recommend solutions to fixing mistakes you can�t find or having trouble
with:
- Walk away and come back to it,
- Have another coder look at it;
- Step though your code with your debugger.

Module 3: String Variables


Input
For getting input from the user in python you use the input command.
Input is broken into two parts:
- A message you specify to display to the user.
- User input.
You will use a variable to record the value entered by the user.

Variables
A variable is a place holder or object you can store a value or piece of data
and come back to it later. Variables are named storage locations or objects
that
contain data you can access later or as you need to.
Variables and strings can be combined with the + symbol, you often need to
add punctuation or spaces to display the output properly.
Variables contents can be manipulated with functions, for example you can use
the .lower() function to change a string to all lowercase.
Functions are a section of a program that performs a specific task.
Naming Variables and Guidelines
Variables are named by you, a variable can have their value change later in
any stage of the code. When naming your variables there are rules:
- You can�t have spaces,
- Variables are case sensitive;
- Cannot start with a number.
Guidelines for creating variables:
- You should use names that make sense or relevant to what they are being
used for, but that are not too long.
- Use a casing scheme, PascalCasing and camelCasing are two common schemes
used.

New Tab
Select and image from the gallery.

Module 4: Storing Numbers


1, Storing Numbers
When working with variables remember you can store numbers as well as
strings, the quotes around the text indicates a string if you want to assign
a numeric
value to the variable you simply enter the number. You can perform math
operation on variables containing numeric values, the operation symbols for
maths in programming are slightly different but many are the same.
Common math operations:
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponent (is for cubing or the power of a value)
% Modulo (is giving you the remainder of a division)
The math rules of order operations are the same in programming as it is in
normal mathematics

2, Formatting Numbers
The + symbol signifies addition in maths and for combining two strings
together, and will not allow you to add a numeric value to the end of a
string.
Therefore, you put a place-holder in your string and after you close off your
string you specify the value you want to put in the place holder.
There are different formats for the place-holders from assigning the amount
of decimal points to leaving spaces in front of your values.
You can also use a Format method to Format numeric values.

3, Inputting Numbers
If you have more than one file in Visual Studio project you will have to
specify which file you want to run, or assign the file you are working on as
the Startup file,
the default startup file is the first file created. Setting up user input is
similar to setting up input for strings however the input function by default
reads you input
as a string so you need to convert your input into a numeric value.

Module 4: Working With Dates And Time


1,Dates
For working with dates you will need to import the date library into your
program.
A library is a collection of precompiled routines and methods for you to use
in your program.
Import is a function for making objects and libraries available to your
program.
Without importing libraries, certain functions won�t be available to you,
they won�t even show up on the InteliSense.

2, Date Formats
The format of your date is important as different countries and companies
have different date formats. The default format is Year-Month-Day.
In python you use strftime function to format dates, it takes in the
parameters; %d for day, %b for month, and %y for year.
There are alternate parameters for the function if you want to display the
date in different formats such as the full year typed out.
If your program uses input to take in a date you will need to convert it to a
date datatype, the strptime function allows you to do this.

3, Working with Time


For working with time you use the same library as date as the library is
called datetime.
The function strftime can also be used to format time the same as for dates
but the parameters are specific to time.

Module 5: Making Designs with code


1, If Statements
When solving problems with your code, your code will need to make decisions
or check conditions for this you use an if statement or an if else statement.
Constraints for checking your if statements:
== is equal to
!= is not equal to
< is less than
> Is greater than
<= is less than or equal to
>= is greater than or equal to

When checking two strings are equal to each other with an if statement, it is
often best to convert both of them to upper or lower case, as python is case
sensitive and will not properly work less both are the same case. There are
generally two different ways to write an if statement you should always
consider
which method makes the most sense and is the simplest.

2,Branching
Branching is when your if condition is not true, so something else happens. A
Boolean variable is one that holds the value true or false.
Code in an else statement is only executed if the condition is not true.

Module 6: Complex Decisions with Code


1, If Then Otherwise
For checking if conditions are true sometimes there is more than one or two
conditions that will affect the outcome,
for this we use a elif statement to check the different conditions.
Ordering of your elif statements is important to be aware of and to test, as
your first condition will be tested if that is true then it won�t check the
rest.

2, Combining Conditions
For combining conditions in you if statements or in functions you use the
logic operators AND, OR.
- For and, both conditions have to be true
- With or, either condition has to be true
You can combine and + or statements using the \.
There is an order of operations the same as in maths so if you are combining
an and & or statement the and will be performed first, the best way to avoid
this is to
use parentheses to make sure you perform each statement separately.

3, Nested If Statements
A nested if statement is an if statement within an if statement.
The indent of the code indicates which line is part of the if statements.

Module 7: Repeating Events


The key points from this module are:
1, For Loops
Turtle is a library you can import into your program to draw lines in
your program. Loops allow you to repeat the same line of code as often as you
want .
For Loops are generally used when you have a piece of code you want to
repeat a number of times. Only the code that is indented in your for loop is
repeated.
2, Nested Loops
A nested loop is one loop inside another loop, what will happen is the
outside loop will execute the number of times you have specified so the
inside loop will
execute the number of times its specified each time the outside loop is
run. A variable can be used as the condition for your loop, this is useful if
you need to
change a value later.
3, Accessing the Loop Value
You can access the steps in a loops range by having the loops count from
one but as most programming languages count from 0, you will be one less than
the
highest value in the range if you count from one. You can tell your for
loop exactly what or how many values are in the for loops range.

Module 8: Repeating Events until Done


The key points from this module are:
1, Loops allow you to repeat the same line of code as often as you want,
while loops allow you to execute code until a particular condition is true.
2, Mistakes are made throughout coding, with loops the problems can be harder
to find as you could have gone through the loop a number of times before the
error happens.
3, With while loops you have to make sure your condition changes or you could
have an infinite loop with no way to end.

Module 9: Remembering Lists


The key points from this module are:
1, Lists allow you to store multiple values.
2, You can store different data types in a list but is not recommended as it
can become confusing for both you and your code when getting data from your
list later.
3, You can create empty lists and add values to it later.
4, Lists count from 0, python does also allow you to count backward with -1
being the last value in the list .
5, For removing from your lists you have two options:
remove() - used when you know the value you want removed
del - used when you know the index number if item you want removed
6, You can change a value in a list by simply reassigning the value to a new
one e.g. list[0] = �new value�. The Index is the position of a value in a
list.
7, If you want the get the length of your list you use the len() function,
useful for using in loops to search though the List.
Module 10: How to Save Information in Files
The key points from this module are:
1, When creating files in your code you need to specify the file name
including the file extension and the access mode.
2, The file extension is what type of file it is, .txt would be a text file.
3, Access mode is whether you can read or write to the file.
4, Access mode parameters:
r � read the file
w- write to the file
a -append to the existing file content
b � open a binary file
r+ or w+ - read and write to the file
5, A csv file is a comma separated values file.
6, When using the write to function to write to a file you need to use \n to
write on a new line.
7, Remember you need to close files after opening them.

Module 11: Reading from Files


The key points from this module are:
For reading from a file you open it the same as you would if you were
creating or writing to the file.
You then use the read function, to read all of its contents or you could use
readline to read one line at a time

There is a library for helping reading csv files that provides many functions
that you would otherwise have to create yourself.
As there is no standard for csv files sometimes the separator or delimiter
could be a semicolon or some other indicator instead of a comma and
your program will need to know what the separator is.

The with statement will automatically close a file after the code is finished
and if an error occurred when writing or reading from the file.

Indentation can be used to make code easier to read and relate codes
together. Indentation will not affect the way your code appears when you run
the project.

Visual studio will automatically add colour to certain aspects of code to


help the readability of code.

Code is defined inside a code block. You define a code block by inserting
'sub' or 'function' followed by 'end sub' or 'end function'. Alternatively,
you can type 'module' followed by 'end module'. Your code should appear
between these.=

It is important to place your message within double quotation marks in your


code.

Module 12: Introduction to Functions


The key points from this module are:

A function is a method or reusable section of code with a name you can call
when you need it to perform a task, without having to rewrite the code again
and again.

To create a function, you use the def keyword and give you function a name,
and write code in the body of the function for what it�s going to do.
Parameters are pieces of data you pass into a function, they often behave
like variables inside the function.

Return passes back a value, variable.

Module 13: Handling Errors


The key points from this module are:

Syntax errors are highlighted with a red squiggly line. The same as MS word
highlighting spelling mistake.

Logic errors are syntactically correct, but they mean that your program
doesn�t do what you wanted it to do. Logic errors can be harder to find,
you would often have to step through code with the debugger.

Runtime errors occur when the code works but something out of the ordinary
crashes the code.

A try/ exception block involves trying a bit of code that may cause an error
and if it fails, the exception is what to do in that event.

If you want to see or display what error happened you can use the
sys.exc_info() to find it you will need to import the sys library.

Linux Course
The main points from this module are:

1, Linux is an open-source operating system that is also available as a


server OS.
2, Linux distribution is a bundle of its core part known as kernel and many
other applications such as spreadsheet and video player.
3, For better performance, most of the Linux servers are non-GUI which
necessitates learning of its fundamentals and commands.
4, A virtual machine (VM) is an isolated computer that can run on any
physical machine knowns as a host.
5, There is a thin layer of software called hypervisor that is responsible
for resource distribution and host-VM communication.
6, To accept text-based commands from users, Linux provides a software
program called shell. The primary job of shell is to take the user input and
provide a program.
7, A process is generated by a program or command, and a program is a
collection of steps.
8, LESS is a commonly used program to read a file while VIM is for editing
and updating a file.
9, When you have a process ID and its current status, you can manipulate the
same process.
10, Package management tools help to install, update and remove third-party
software utilities in Linux.
11,For and loops in Linux help execute instructions numerous times without
writing the code again and again.

You might also like