Python Tutorial 1 – Writing your First Python Program [w/ subs]



00:00:00 – hello everybody and welcome to my python
00:00:02 – tutorial video I felt the need to make
00:00:05 – this video because i watched a lot of
00:00:08 – YouTube videos on programming and you
00:00:11 – know how how other people found ways of
00:00:13 – doing things and I still notice that
00:00:16 – there's a lot of people who still have
00:00:17 – questions i kinda wanted to make a
00:00:20 – really basic tutorial video and kind of
00:00:26 – go over everything with that happens in
00:00:30 – the program and try to spell it out or
00:00:32 – take time to take the time and kind of
00:00:34 – spell out everything that's happening in
00:00:36 – the video which I notice a lot of a lot
00:00:39 – of people who don't actually do that but
00:00:42 – without further ado I'm i get right into
00:00:45 – it i'm using python 2.7 for this I used
00:00:51 – to every I know other people are all
00:00:53 – were using 2.7 you should be using three
00:00:55 – or whatever but I don't know to have it
00:01:00 – had to be honest there's a lot of people
00:01:02 – I've learned a lot in 2.75 watch a lot
00:01:06 – of tutorials that use 2.7 so I don't
00:01:09 – know if I'm really ready to bridge the
00:01:11 – gap in 23 there's still a lot of support
00:01:15 – for 2.7 and a lot of libraries and
00:01:19 – whatnot 42.7 which so I'm just going to
00:01:23 – be using 2.7 upon a link to the Python
00:01:27 – website in the description below so you
00:01:33 – can go there you can download Python
00:01:36 – it's absolutely free
00:01:38 – I mean be using idol which is a
00:01:43 – integrated development environment I
00:01:46 – think that's the acronym for it but ide
00:01:50 – for python it comes with python you get
00:01:53 – it for free and everything so let's get
00:01:57 – right into it functions
00:02:00 – first off functions what are functions
00:02:02 – functions are groups of code ment to do
00:02:07 – something for you so it's basically a
00:02:11 – simplified way I wouldn't really say
00:02:14 – simplified but you make a function code
00:02:19 – underneath it whenever you run that
00:02:21 – function it automatically does that
00:02:23 – group code there's just about I mean
00:02:28 – there's what we're going to be using a
00:02:29 – couple different functions today it's
00:02:31 – gonna be really hopefully really easy
00:02:34 – and straightforward to follow if not
00:02:39 – just leave me a comment below and I'll
00:02:41 – do my best to explain it but we're going
00:02:43 – to be using a main function and Maine is
00:02:46 – just when you think of Maine you want
00:02:49 – you wanted to do everything that you
00:02:53 – need your program to do within one
00:02:55 – function that way you can just call one
00:02:57 – function and then you're good you can
00:03:00 – call from other you can call other
00:03:01 – functions within main which we will be
00:03:04 – doing
00:03:05 – it's pretty it's pretty simple i think
00:03:08 – once you see it will make sense for you
00:03:10 – print print is a function that displays
00:03:14 – text to the screen it's really about is
00:03:18 – it's a Python built-in it's just it just
00:03:22 – works that's how it works
00:03:24 – display the message to the screen input
00:03:28 – input gets a datatype from a user gets
00:03:33 – value from a user so if we do raw input
00:03:37 – and then within the parentheses you
00:03:41 – enter a string or something that you
00:03:44 – want to say to the user so you say enter
00:03:47 – a value or enter a variable or something
00:03:51 – like that
00:03:52 – enter value for variable but over
00:03:55 – strings and data types of stuff will use
00:03:57 – in just a moment the raw input all you
00:03:59 – what you have to know is it gets the
00:04:01 – value of side get some kind of string or
00:04:04 – get some kind of value from a user the
00:04:07 – float float data type in
00:04:12 – python is a numerical data as numerical
00:04:16 – value but it has a decimal place so you
00:04:19 – can use like division and that kind of
00:04:22 – thing with it it just converts whatever
00:04:25 – data types that you give you throw at it
00:04:27 – into a float so data types the string
00:04:32 – strings are just groups of groups
00:04:35 – attacks groups of words groups of
00:04:37 – letters error encompass by quotations
00:04:43 – either single quotes or double quotes
00:04:45 – and that's just a group of tax that's
00:04:49 – all it is
00:04:50 – there's nothing fancy really fancy about
00:04:52 – strings afloat is a numerical data type
00:04:56 – like I said it's a whole number with a
00:04:58 – decimal that's the following is so 10.0
00:05:01 – that's that's a float next we're going
00:05:05 – to get into operations plus is ad- is
00:05:11 – subtract those two are pretty
00:05:12 – straightforward but multiply and divide
00:05:15 – multiply his asterisk which is shift
00:05:19 – eight we have I think it's /a maybe it's
00:05:22 – backslash I like I should really learn
00:05:24 – that did I should really learn what each
00:05:26 – one is called but it's the one right
00:05:29 – next to your shift or it's on the keypad
00:05:31 – to your right at the great above the
00:05:33 – eight so I'm going to comment this out
00:05:38 – whole what am i doing trip of these
00:05:45 – triple single quotes are multi-line
00:05:48 – comment and a comment is basically just
00:05:52 – something for you
00:05:54 – the developer or you're working with
00:05:57 – multiple people you can pass this over
00:06:00 – and you can leave comments like this
00:06:02 – this just said this is sort of synapses
00:06:05 – of the program get two numbers
00:06:08 – ok so our program is get two numbers
00:06:11 – from the user display the some
00:06:13 – difference product and quotient so
00:06:16 – that's what the program that we're
00:06:17 – drinking today is going to do and I'm
00:06:20 – actually taking these from my class that
00:06:23 – has
00:06:25 – does pseudocode so it's really about
00:06:29 – planning out your really these are real
00:06:32 – examples of real programs in like a
00:06:36 – college curriculum and everything so get
00:06:39 – two numbers from user displayed some
00:06:41 – difference product and quotient
00:06:43 – ok so we wanted the first thing we want
00:06:46 – to do is we want to get two numbers from
00:06:48 – the user and we want to put them in a
00:06:50 – way that we can use
00:06:54 – I lied the first thing that we want to
00:06:56 – do is create our main function and this
00:06:59 – is the fine main so think about is
00:07:02 – defined the ESI think that's what
00:07:05 – actually stands for but we're defining
00:07:07 – our main function so we've been we
00:07:12 – always end our functions with a colon or
00:07:14 – are when we're defining them so what do
00:07:18 – we want to put within our main we want
00:07:20 – everything about this program put in
00:07:22 – Maine so we're going the first thing we
00:07:26 – have to get his get two numbers from the
00:07:28 – user so use x and y 4 variables and x is
00:07:33 – going to equal the raw input of their
00:07:41 – it's just going to get Ryan put then
00:07:44 – let's get a string in here so we can
00:07:46 – give the user some instruction to say
00:07:50 – enter number number one and you put
00:07:57 – anything within anything pretty much
00:08:00 – anything within a string and it will
00:08:03 – it's just verbatim like letter for
00:08:06 – letter whatever is in those quotations
00:08:09 – will go out the problem with raw input
00:08:12 – right now is that it's going to take
00:08:15 – input and the input or whatever we put
00:08:17 – even if it's a number is going to be a
00:08:19 – string as a data type so after we get
00:08:23 – our raw input or at the same time I
00:08:26 – guess we can convert this to a float
00:08:29 – which is that number plus a decimal so
00:08:32 – what this is going to do
00:08:33 – it's going to say raw input it's going
00:08:37 – to display enter number 12 the screen
00:08:40 – when you enter a number and then hit
00:08:42 – enter type in a number and hit enter
00:08:44 – it's going to convert that number to a
00:08:48 – float so give it a decimal place and
00:08:51 – then it's gonna sign that value to the
00:08:53 – variable X and assigning it to a
00:08:57 – variable makes it so that we can do
00:08:59 – something with it later on this stored
00:09:02 – in our memory now we're going to do the
00:09:05 – same thing with why enter number two
00:09:15 – ok and notice that there's the double
00:09:19 – quotation or the double parentheses
00:09:21 – every function has to have a beginning
00:09:25 – and an end parentheses so we're using
00:09:28 – raw input display this to the screen and
00:09:32 – then convert it to a float so that's all
00:09:35 – that's going on and then stores that
00:09:37 – value as x and y respectively
00:09:41 – alright so hopefully you're still
00:09:43 – following with me
00:09:45 – we're using one function to get the
00:09:47 – input and we're using another function
00:09:49 – to convert it to a usable data type
00:09:55 – ok so we want to display the some
00:09:57 – difference product and quotient the next
00:10:01 – thing what i would do is print and print
00:10:05 – as a function that displays something to
00:10:07 – screen the sprint is a special function
00:10:09 – where you don't have to use parentheses
00:10:13 – so i'm not going to use parentheses here
00:10:14 – i'm not sure if it's that way in Python
00:10:18 – 3
00:10:19 – I think there are some print differences
00:10:21 – but i'm not going to try and get into
00:10:23 – that so now we have two variables x and
00:10:28 – y that hold float data types right so
00:10:32 – that's number with a decimal so now
00:10:35 – let's print X plus y will print X minus
00:10:41 – y
00:10:42 – folks doesn't matter if you put the
00:10:45 – space but it's common practice + space
00:10:48 – in between them because it looks neater
00:10:52 – it's a little bit easier to follow
00:10:53 – what's going on so we're going to print
00:10:57 – X plus y print X minus y print x times y
00:11:02 – x divided by Y to the screen and then I
00:11:07 – know I know we're not done 11 minutes in
00:11:09 – but uh now that we have our function our
00:11:14 – main function defined that this is all
00:11:17 – we need the program to do we're done
00:11:19 – what we want to do is we want to call
00:11:22 – menor run main defining main doesn't run
00:11:27 – it it just sets up a structure for the
00:11:31 – program it says if you want to use it we
00:11:33 – know what to do with we know what to do
00:11:35 – when you say main so we're going to call
00:11:38 – main now and then when that's it we're
00:11:43 – done
00:11:43 – so let's run this program let me see if
00:11:47 – I can get this see if i can get this
00:11:51 – running i think this is there we go
00:11:56 – alright so the first part is enter
00:12:03 – number one so this is I i don't know if
00:12:06 – i can do a split screen thing here
00:12:08 – that's not going to let me run this but
00:12:14 – screen thing here
00:12:15 – alright so enter number one that's the
00:12:18 – string of that's the string of the raw
00:12:22 – input that we put in so inside the raw
00:12:25 – input parentheses we put enter number
00:12:28 – one and that's where it is so enter
00:12:31 – number one say 10
00:12:34 – so when we hit enter this is going to be
00:12:37 – converted to a float datatype from a
00:12:39 – string to remember raw input gives us a
00:12:42 – string and then it's going to be
00:12:44 – assigned to the variable X so that's
00:12:47 – what happened it's 10 now it's 10.0 and
00:12:50 – x equals 10.0
00:12:53 – so number two let's just do 20 for the
00:12:56 – sake of I don't know I felt like doing
00:12:59 – 2020 is we're going to enter it's going
00:13:04 – to take the raw input and it's that's 20
00:13:08 – float functions cuz we're going to
00:13:11 – convert it into a converted to 20.0 and
00:13:15 – then its assigned the value Y and then
00:13:18 – since we printed X plus y going to do
00:13:21 – ten plus 20 equals 30 point-0 because
00:13:25 – they're both floats 10-20 it's going to
00:13:30 – give us negative 10 point no 10 * 2200
00:13:35 – and then 10/20 is going to give us 0.5
00:13:41 – or half so let's go back to this and one
00:13:48 – thing that i want to show you that you
00:13:50 – can do for a little bit more
00:13:51 – clarification of what's going on with
00:13:54 – the program just make a little prettier
00:13:56 – to read for the user X plus y is going
00:14:00 – to return that value X minus y return
00:14:02 – that value etc but we can do is we can
00:14:06 – separate this with a comma and then
00:14:08 – enter a string play x + y and i must say
00:14:14 – the string is the sum and i'm going to
00:14:19 – do is the difference
00:14:24 – notice the comma is the product is the
00:14:34 – quotient quot quotient
00:14:38 – alright so each object in print
00:14:44 – I mean this is my understanding of it
00:14:46 – but X plus y would be considered like
00:14:49 – one object you can do an equation type
00:14:52 – of deal and that was going to return 11
00:14:56 – value right X plus y is going to be one
00:14:59 – number so do comma after that you have
00:15:03 – to separate items in a in the way
00:15:06 – from within the print function x comma
00:15:08 – so we're doing X plus y comma and then
00:15:13 – we're adding a string onto the end of it
00:15:16 – so we're saying we're saying the string
00:15:18 – is the sum so say an X plus y it's going
00:15:21 – to return that value and then it's going
00:15:23 – to say print the string is the sum right
00:15:26 – after it that way the person can
00:15:27 – actually know what's going on with that
00:15:30 – let's try running this
00:15:35 – there we go oops I don't know what's
00:15:39 – going on but uh I know you guys couldn't
00:15:44 – see anything but my screen went haywire
00:15:46 – enter number one right so let's do 10
00:15:50 – and plenty again see now it's printing
00:15:53 – 30 is the sum- 10 is the difference is
00:16:00 – the product and then is the quotient on
00:16:03 – the end of all of those values that just
00:16:05 – gives our user a little bit more
00:16:07 – readability so I don't have a long video
00:16:12 – if you have any questions or comments
00:16:14 – please put them in the comments section
00:16:17 – below and I'll do my best to help you
00:16:19 – out
00:16:20 – thanks for watchin


Video Url:
http://youtu.be/sK9wumevAPw

(Visited 12 times, 12 visits today)

Comments

comments