Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
Python Notes
Iphone or iPad you need to install a couple of other things first so you go to
the App Store and search for Pycharm
...
Now
...
Here in your downloads folder
...
py file
...
The first thing you 're going to do is create a new
project so let's do that by clicking on this green plus sign here in your project
explorer window and type in Python
...
Now
let's choose a location for your project so we're going to choose a folder on
our computer called projects and then click on the create Button Now let's
change some settings inside of Pycharm
...
To
want to do is change the language of your project to Python, So inside of
pycharm
...
Now next thing you 're going
to want to do is set up your project folder so inside of pycharm go to File >
Settings > Project Structure and in the Project Folder section click on the
Browse button and then select the folder where you want your project files to
live so now Your project is set up and ready to go all right let's start writing
some code
...
In Python
...
py file and enter this code here
...
py now let's run our
program by clicking on this green run button here inside of pycharm and
you'll see that our program has printed out [UNK] world!" all right that's our
first simple code block in Python now Let's take a look at some more code
blocks in Python
...
py file again and enter this code def [UNK] [UNK] world!") all right
so we've defined a function called say —hello() and inside of say —hello()
we're going to print out [UNK] world!" now let's save our file once again say
we want to declare a variable called price
...
We would put a colon and then the value of
that variable
...
99
...
We can do that by simply writing print price
and then after that we would put a period and then the value of the variable
...
99 alright
...
We can do that by simply typing
new value for price and then after that we would type a colon and then the
new value of the variable
...
00
alright
...
We can do that by
simply typing delete price and then after that we would type a period and
then hit enter so In this case, the code would delete the variable called price
Alright
...
Let's say we have a list of items and we want
to display
...
We would type for item in list, and
then after that we would type parenthesis, then the list item and then after
that hit enter so In this case, the code would run for each item in the list called
list and then it would go inside the parentheses and it would assign the item
inside those parentheses to the variable called item
...
You could do that
by simply typing different values for parenthesis
...
So now you understand how to use a for loop alright
...
Functions are blocks of code
that you can use in your python programs to simplify your code or to make it
more powerful
...
Okay now let's say we wanted to call this
function inside our for loop so to do that we would type square(12
...
In this case the code would run and it
declare and use variables in python
...
Then in the App Store click on the
install button
...
Once Pycharm is installed, you can open it up by clicking
on this icon
...
You should also have a
...
So
let's open that up now
...
This is the name of your project
...
So first thing you 're going to
...
Go to File > Settings > Project Settings and in the Languages section
change Python to the language of your project
...
We're going to start with the simplest code possible and that's a
hello world program
...
A Hello world program is simply a program
that prints out hello world so let's open up our
...
Here import sys [UNK] world!") all right so we've imported the Sys module and
then we've printed out [UNK] world!" now Let's save our file by clicking on this
green button here in your editor window and call it Hello
...
First thing we'll want to do is create a variable, so let's open
up our hello
...
We would type price and then after
we type the name of the variable
...
So in this case, the value of this variable will be 12
...
So we can
use this variable anywhere inside our Python code now let's say we want to
print the value of this variable
...
So in this case the code would print out 12
...
Now let 's say we
wanted to change the value of this variable
...
So in this case the code would print out 13
...
Now let's say we wanted to delete this variable
...
Now let's talk about lists
...
each item in turn on our application window so to do that we need
to use a for loop so to declare a for loop
...
So in this case, the code
would print out apple Banana cherry pineapple, so you can see how this works
if you wanted to change what was inside those parentheses
...
So in this case, I typed apple
Banana cherry pineapple
...
Now last but not least let's talk about functions
...
You can think of functions as mini-programs inside your
python program, So you can see here is a function called square which is just a
simple function that takes one parameter which is called a number, and it
returns the square of that number
...
99) inside
our for loop and after that hit enter so
...
You run the program and you get this message
...
So this is how we can use the input function in Python to read a value
from the user now
...
So let me show you how we do that so
we first create a variable called message and set it to the string 'please enter
your message' now we use the print function to print our message on the
terminal window so you can see it here now
...
What we want to do is display this message for as long as the user remains in
our program
...
So In this case the condition is that our message
variable is not empty and that 's why we put a comma after while because that
's what tells Python to keep looping while this condition is met okay now if
you type exit out of our program right now you will get an error message
because our while loop condition is not met Okay
...
So we can keep track of how many times our while loop
condition has been met
...
Now if you run our program again and type exit out
...
Now Let's add another counter
and set it to 2 now
...
You
will see that our while loop condition has been met six times now let's add
another counter and set it to 3
...
Now
...
You will see that our while loop
condition has been met 12 times
...
So next time I 'll show you how to read
values from the user and how to write values to the user
...
THe error was caused by
attempting to subtract a string from an integer, which Python does not
support
...
function is the string that we got from the input
function now let's run the program so 10 and 20
...
This passage, the author explains how to solve a problem in Python where two
numbers are being combined together as strings
...
THe
sum of the two numbers is then calculated using the float function, which
converts both numbers to their
...
Finally, the sum of
the two numbers is displayed on the terminal
...
However,
...
Additionally,
...
We wanted to calculate the
sum of the two numbers
...
This passage provides some insights
into how to solve a problem in Python where two numbers are being
combined together as strings
...
The sum of
the two numbers is then calculated using the float function, which converts
both numbers to their numeric representations
...
You run the program and you get this message
...
So this is how we can use the input function in Python to read a value
from the user now
...
So let me show you how we do that so
we first create a variable called message and set it to the string 'please enter
your message' now we use the print function to print our message on the
terminal window so you can see it here now
...
What we want to do is display this message for as long as the user remains in
our program
...
So In this case the condition is that our message
variable is not empty and that 's why we put a comma after while because that
's what tells Python to keep looping while this condition is met okay now if
you type exit out of our program right now you will get an error message
because our while loop condition is not met Okay
...
So we can keep track of how many times our while loop
condition has been met
...
Now if you run our program again and type exit out
...
Now Let's add another counter
and set it to 2 now
...
You
will see that our while loop condition has been met six times now let's add
another counter and set it to 3
...
Now
...
You will see that our while loop
condition has been met 12 times
...
So next time I 'll show you how to read
values from the user and how to write values to the user
...
THe error was caused by
attempting to subtract a string from an integer, which Python does not
support
...
function is the string that we got from the input
function now let's run the program so 10 and 20
...
This passage, the author explains how to solve a problem in Python where two
numbers are being combined together as strings
...
THe
sum of the two numbers is then calculated using the float function, which
converts both numbers to their
...
Finally, the sum of
the two numbers is displayed on the terminal
...
However,
...
Additionally,
...
We wanted to calculate the
sum of the two numbers
...
This passage provides some insights
into how to solve a problem in Python where two numbers are being
combined together as strings
...
The sum of
the two numbers is then calculated using the float function, which converts
both numbers to their numeric representations
...
Ia, you can see the course variable has been updated to say y y y y now I 'll
delete that line and let's run the program again
...
We
can also use the find method to look for a specific character in our string
...
We could do
course
...
So this
is another really useful function for finding specific values in strings
...
So if we pass
course
...
Now let's use this array
...
We can
use the len function to get the length of our array and then we can use the
range function to see if our number is between 0 and 9
...
So we would type 5, 6, 7, 8, 9, and so on now
...
This is going to print 1 because 5
...
Which is 1
...
Let 's print 10
divided by 3
...
Which is 3
...
In this case, we have a string that
has two integers in it 10 and 5 and we want to divide them
...
We
can use the / operator, so we can write 10 / 5
...
Because
10 is going to be divided by 5
...
'm going to declare a variable called
a and set it to 10 plus 5 and then I 'm going to declare another variable called
b and set it to 5
...
two values, so we can use the == operator
...
So in this case it's going to return True
...
all right
...
5
...
This is again a basic math question that
unfortunately, a lot of people fail to answer
...
5 because 10
...
5 equals 15
...
Ia, you can see the course variable has been updated to say y y y y now I 'll
delete that line and let's run the program again
...
We
can also use the find method to look for a specific character in our string
...
We could do
course
...
So this
is another really useful function for finding specific values in strings
...
So if we pass
course
...
Now let's use this array
...
We can
use the len function to get the length of our array and then we can use the
range function to see if our number is between 0 and 9
...
So we would type 5, 6, 7, 8, 9, and so on now
...
This is going to print 1 because 5
...
Which is 1
...
Let 's print 10
divided by 3
...
Which is 3
...
In this case, we have a string that
has two integers in it 10 and 5 and we want to divide them
...
We
can use the / operator, so we can write 10 / 5
...
Because
10 is going to be divided by 5
...
'm going to declare a variable called
a and set it to 10 plus 5 and then I 'm going to declare another variable called
b and set it to 5
...
two values, so we can use the == operator
...
So in this case it's going to return True
...
all right
...
5
...
This is again a basic math question that
unfortunately, a lot of people fail to answer
...
5 because 10
...
5 equals 15
...
This expression is going to be false because the value of price is 5
...
then we 're
going to have the not operator and the result of this expression is going to be
true because price doesn't equal 10 or 5
...
You can also use these operators in
combination with each other
...
go back to
...
Then so we add a colon and see what
happens when I press enter now the character is indented and this represents
a block of code
...
Let me show you so
we 're going to print
...
Because here we have a single
quote as an apostrophe, so I could n't declare a string like this
...
The carrot is indented so the code that right here will be part of
our if block and it will get executed
...
So here we can
print a second message drink plenty of water now to terminate this block
...
The carrot is no longer indented
...
Now in C-based programming languages
like C plus C, sharp, Java and Javascript
...
So you start a block of code using a left brace and then end it
using a right brace
...
So we use
indentation to represent a block of code okay so in this case
...
Now let 's go
back to our if statement and let's say if temperature is greater than or equal to
30, then we want to print a message, saying it's cold today
...
Our comparison
operators so we type temperature greater than or equal to 30
...
The
character is indented and this represents a block of code
...
So I
type K and press enter now
...
2 to get the
pounds
...
It says to divide the weight by 12 to
get the kilograms so I type KD and press enter now It asks me if I want to
convert to pounds or kilograms
...
It tells me
the result in pounds
...
Now let's take a look at
our
...
One is that the weight is in
kilograms
...
So
...
This expression is going to be false because the value of price is 5
...
then we 're
going to have the not operator and the result of this expression is going to be
true because price doesn't equal 10 or 5
...
You can also use these operators in
combination with each other
...
go back to
...
Then so we add a colon and see what
happens when I press enter now the character is indented and this represents
a block of code
...
Let me show you so
we 're going to print
...
Because here we have a single
quote as an apostrophe, so I could n't declare a string like this
...
The carrot is indented so the code that right here will be part of
our if block and it will get executed
...
So here we can
print a second message drink plenty of water now to terminate this block
...
The carrot is no longer indented
...
Now in C-based programming languages
like C plus C, sharp, Java and Javascript
...
So you start a block of code using a left brace and then end it
using a right brace
...
So we use
indentation to represent a block of code okay so in this case
...
Now let 's go
back to our if statement and let's say if temperature is greater than or equal to
30, then we want to print a message, saying it's cold today
...
Our comparison
operators so we type temperature greater than or equal to 30
...
The
character is indented and this represents a block of code
...
So I
type K and press enter now
...
2 to get the
pounds
...
It says to divide the weight by 12 to
get the kilograms so I type KD and press enter now It asks me if I want to
convert to pounds or kilograms
...
It tells me
the result in pounds
...
Now let's take a look at
our
...
One is that the weight is in
kilograms
...
So
...
170 in pounds 170 in kilograms
...
[UNK] condition in the while loop must be true for the code in
the block to get executed
...
tell Python that we are declaring
a list and then we assign it the value of a list
...
Names is a list of
strings okay now let me show you how we would print out the contents of the
list names so I 'm going to use the print function and I 'm going to use the
string format, so I 'm going to tell Python to print the list value and then I 'm
going to use
...
Okay so now Let me change this program so that it prints out the names
of all the students in my class
...
Okay
...
Okay now let me change this program so that it prints
out the average grades of all the students in my class
...
Okay Now let me run this program and we see that it's printing
out the average grades of all the students in
...
py and I am going to import some modules
...
This passage, you
learn about three types of data in [UNK] numbers, Booleans,, and strings
...
You also
learn about print functions and string formats
...
THe insights that can be gleaned from this
passage are as [UNK] [UNK] while loop can be used to repeat a block of code
multiple times
...
[UNK] the variable i within the while loop is
necessary for it to keep track of the counter
...
So in this case
...
an asterisk to indicate that I want to print every element in the
list
...
So here we are creating a new variable called
students and we're assigning it the value of a list, which is a list of strings
...
Now let me run this program and we see that it's printing out all the
students in my class
...
So here we are creating
a new variable called grades and we're assigning it the value of a list, which is
a list of floats
...
My class okay now Let me create
a new file called practice
...
So first I
am going to import the math module so we can use mathematical operations
like addition, subtraction,, multiplication, and division In
...
You
learn about lists, which are used for representing a list of objects
...