100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Python Notes

Rating
-
Sold
-
Pages
4
Uploaded on
06-03-2023
Written in
2022/2023

Python for Beginners - Learn Python in 1 Hour Programming with Mosh Iphone or iPad you need to install a couple of other things first so you go to the App Store and search for Pycharm. Then in the App Store click on the install button. Now. Once Pycharm is installed, you can open it up by clicking on this icon. Here in your downloads folder. You should also have file. So let's open that up now. The first thing you 're going to do is create a new project so let's do that by clicking on this gr een plus sign here in your project explorer window and type in Python. This is the name of your project. N ow lef's choose a location for your project so we're going to choose a folder on our computer called projec ts and then click on the create Button Now let's change some settings inside of Pycharm. So first thing yo u 're going to. To want to do is change the language of your project to Python, So inside of pycharm. Got o File > Settings > Project Settings and in the Languages section change Python to the language of your project. 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 s elect the folder where you want your project friles to live so now Your project is set up and ready to go all ri ght let's start writing some code. We're going to start with the simplest code possible and thať's a hello wo rld program. In Python. A Hello world program is simply a program that prints Out hello world so let's open up file and enter this code here. Here import sys [UNK] world!") all right so we've imported the Sys module and then we' ve printed out [UNKJ world!" now Lets save our file by clicking on this green button h ere in your editor window and call it H now let's run our program by clicking on this green run butto n here inside of pycharm and you'll see that our program has printed out [UNK] world!" all right thať's our fi rst simple code block in Python now Let's take a look at some more code blocks in Python. First thing we'l I want to do is create a variable, so let's open up our file again and enter this code def [UNK] [UN K] 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 type price and then after we type the name of the variable. We would put a colon and then the value of that variable. So in this case, the value of this variable will be 12.99. So we can use this variable anywhere inside our Python code now let's say we want to print the value of this variable. 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. S o in this case the code would print out 12.99 alright. Now let 's say we wanted to change the value of this variable. We can do that by simply typing new value for price and then after that we would type a colon an d then the new value of the variable. So in this case the code would print out 13.00 alright. Now let's say we wanted to delete this variable. We can do that by simply typing delete price and then after that we wou ld type a period and then hit enter so In this case, the code would delete the variable called price Alright. Now let's talk about lists. Let's say we have a list of items and we want to display. 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. We would type for ite m 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 parenthes es and it would assign the item inside those parentheses to the variable called item. So in this case, the c Ode would print out apple Banana cherry pineapple, so you can see how this works if you wanted to chan ge what was inside those parentheses. You could do that by Simply typing different values for parenthesis So in this case, I typed apple Banana cherry pineapple. So now you understand how to use a for loop alr ight. Now last but not least let's talk about functions. Functions are blocks of code that you can use in you python programs to Simplify yOur code or to make it more powerful. You can think of functions as mini-pr ograms inside your python program, So you can see here is a function called square which is just a simpl e function that takes one parameter which is called a number, and it returns the square of that number. O kay now let's say we wanted to call this function inside our for loop so to do that we would type square(12. 99) inside our for loop and after that hit enter so. In this case the code would run and it declare and use v ariables in python. You run the program and you get this message. The age of John Smith is 1990 okay. So this is how we c an use the input function in Python to read a value from the user now. In addition to reading values from t he user, we also have the ability to write values to the user. So let me show you how we do that so we firs t create a variable called message and set it to the string 'please enter your message' now we use the pri nt function to print our message on the terminal window so you can see it here now. Let's run our program and see what happens so please enter your message so we get this message now. VWhat we want to do i s display this message for as long as the user remains in our program. So we use the while loop sO we ty pe while True which means while the condition is True. So In this case the condition is that our message v ariable 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 er ror message because our while loop condition is not met Okay. So now let's add a counter to our program .So we can keep track of how many times our while loop condition has been met. So we add a variable c alled counter and set it to 1. Now if you run our program again and type exit out. of it, you will see that our while loop condition has been met four times. Now Let's add another counter and set it to 2 now. If you ru n our program again and type exit out of it. You will see that our while loop condition has been met six tim es now lef's add another counter and set it to 3. Now lf you run our program again and type exit out of it, y ou will see that our while loop condition has been met nine times now finally leť's add another counter and set it to 4. Now. If you run our program again and type exit out of it. You will see that our while loop condit ion has been met 12 times. So this is how we can use the while loop in Python to write a value to the user So next time || show you how to read values from the user and how to write values to the user. THe pa ssage discusses how an error occurred in a program. THe error was caused by attempting to subtract a st ring from an integer, which Python does not support. TO solve the problem, the author converted the strin g to an integer and sOlved the problem. function is the string that we got from the input function now let's run the program so 10 and 20.1 and here 's the result In. This passage, the author explains how to solve a problem in Python where two numberS are being combined together as strings.. THe first number is rea d into a variable, and the second number is read into a second variable.. THe sum of the fwo numbers is t hen calculated using the float function, which converts both numbers to their. numeric representations. Fi nally, the sum of the two numbers is displayed on the terminal. One way to solve This problem would be t o use the int function, which would convet both numbers to integers. However,. Since we're dealing with strings, we need to use the float function instead. Additionally,. Since we're not required to use the float fu nction, we could have just called it at the time. We wanted to calculate the sum of the two numbers. IN co nclusion,. This passage provides some insights into how to solve a problem in Python where two numbers are being combined together as strings.. The first step is to read in the first number into a variable, and th e second step is to read in the second number.. The sum of the fwo numbers is then calculated using the float function, which converts both numbers to their numeric representations.. Finally, the sum of the two numbers is displayed on the terminal. la, you can see the course variable has been updated to say y yyy now I 'll delete that line and let's run t he program again. You should see two now. We can also use the find method to look for a specific charac ter in our string. So if we wanted to find the character at index 3 in our string. We could do (3) and 2s Ia OL cAn see that function returned the value 4 So thie ie another reall/ uSeful function for

Show more Read less
Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
March 6, 2023
Number of pages
4
Written in
2022/2023
Type
Class notes
Professor(s)
Koodalarasu
Contains
All classes

Subjects

Content preview

Python for Beginners - Learn Python in 1 Hour
Programming with Mosh

Iphone or iPad you need to install a couple of other things first so you go to the App Store and search for
Pycharm. Then in the App Store click on the install button. Now. Once Pycharm is installed, you can open
it up by clicking on this icon. Here in your downloads folder. You should also have a.py file. So let’s open
that up now. The first thing you ’re going to do is create a new project so let’s do that by clicking on this gr
een plus sign here in your project explorer window and type in Python. This is the name of your project. N
ow let’s choose a location for your project so we’re going to choose a folder on our computer called projec
ts and then click on the create Button Now let’s change some settings inside of Pycharm. So first thing yo
u ’re going to. To want to do is change the language of your project to Python, So inside of pycharm. Go t
o File > Settings > Project Settings and in the Languages section change Python to the language of your
project. 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 s
elect the folder where you want your project files to live so now Your project is set up and ready to go all ri
ght let’s start writing some code. We’re going to start with the simplest code possible and that’s a hello wo
rld program. In Python. A Hello world program is simply a program that prints out hello world so let’s open
up our.py file and enter this code here. 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 h
ere in your editor window and call it Hello.py now let’s run our program by clicking on this green run butto
n here inside of pycharm and you’ll see that our program has printed out [UNK] world!" all right that’s our fi
rst simple code block in Python now Let’s take a look at some more code blocks in Python. First thing we’l
l want to do is create a variable, so let’s open up our hello.py file again and enter this code def [UNK] [UN
K] 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 type price and then after we type the name of the variable. We would put a colon and then the
value of that variable. So in this case, the value of this variable will be 12.99. So we can use this variable
anywhere inside our Python code now let’s say we want to print the value of this variable. 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. S
o in this case the code would print out 12.99 alright. Now let ’s say we wanted to change the value of this
variable. We can do that by simply typing new value for price and then after that we would type a colon an
d then the new value of the variable. So in this case the code would print out 13.00 alright. Now let’s say
we wanted to delete this variable. We can do that by simply typing delete price and then after that we wou
ld type a period and then hit enter so In this case, the code would delete the variable called price Alright.
Now let’s talk about lists. Let’s say we have a list of items and we want to display. 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. We would type for ite
m 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 parenthes
es and it would assign the item inside those parentheses to the variable called item. So in this case, the c
ode would print out apple Banana cherry pineapple, so you can see how this works if you wanted to chan
ge what was inside those parentheses. You could do that by simply typing different values for parenthesis
. So in this case, I typed apple Banana cherry pineapple. So now you understand how to use a for loop alr
ight. Now last but not least let’s talk about functions. Functions are blocks of code that you can use in you
r python programs to simplify your code or to make it more powerful. You can think of functions as mini-pr
ograms inside your python program, So you can see here is a function called square which is just a simpl
e function that takes one parameter which is called a number, and it returns the square of that number. O
kay now let’s say we wanted to call this function inside our for loop so to do that we would type square(12.
99) inside our for loop and after that hit enter so. In this case the code would run and it declare and use v
ariables in python.

You run the program and you get this message. The age of John Smith is 1990 okay. So this is how we c
an use the input function in Python to read a value from the user now. In addition to reading values from t
he user, we also have the ability to write values to the user. So let me show you how we do that so we firs
t create a variable called message and set it to the string ’please enter your message’ now we use the pri
nt function to print our message on the terminal window so you can see it here now. Let’s run our program
$8.39
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
koodalarasu

Get to know the seller

Seller avatar
koodalarasu
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions