Output

Introduction to Programming Input, Process, Output
12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.43
List Price:  €93.47
You save:  €28.04
£55.38
List Price:  £79.12
You save:  £23.73
CA$95.75
List Price:  CA$136.80
You save:  CA$41.04
A$107.11
List Price:  A$153.03
You save:  A$45.91
S$95.36
List Price:  S$136.24
You save:  S$40.87
HK$547.90
List Price:  HK$782.75
You save:  HK$234.85
CHF 63.27
List Price:  CHF 90.39
You save:  CHF 27.12
NOK kr772.60
List Price:  NOK kr1,103.76
You save:  NOK kr331.16
DKK kr487.88
List Price:  DKK kr697.01
You save:  DKK kr209.12
NZ$117.84
List Price:  NZ$168.36
You save:  NZ$50.51
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,700.43
List Price:  ৳11,001.09
You save:  ৳3,300.65
₹5,837.33
List Price:  ₹8,339.41
You save:  ₹2,502.07
RM333.67
List Price:  RM476.70
You save:  RM143.02
₦92,489.99
List Price:  ₦132,134.22
You save:  ₦39,644.23
₨19,533.24
List Price:  ₨27,905.82
You save:  ₨8,372.58
฿2,588.46
List Price:  ฿3,697.97
You save:  ฿1,109.50
₺2,275.23
List Price:  ₺3,250.47
You save:  ₺975.23
B$358.08
List Price:  B$511.57
You save:  B$153.48
R1,314.42
List Price:  R1,877.82
You save:  R563.40
Лв127.95
List Price:  Лв182.79
You save:  Лв54.84
₩96,452.39
List Price:  ₩137,795.03
You save:  ₩41,342.64
₪267.23
List Price:  ₪381.78
You save:  ₪114.54
₱4,034.64
List Price:  ₱5,764.02
You save:  ₱1,729.38
¥11,065.06
List Price:  ¥15,807.91
You save:  ¥4,742.85
MX$1,201.03
List Price:  MX$1,715.83
You save:  MX$514.80
QR255.83
List Price:  QR365.49
You save:  QR109.65
P965.79
List Price:  P1,379.76
You save:  P413.97
KSh9,296.24
List Price:  KSh13,280.92
You save:  KSh3,984.67
E£3,349.82
List Price:  E£4,785.67
You save:  E£1,435.84
ብር4,026.64
List Price:  ብር5,752.60
You save:  ብር1,725.95
Kz58,375.85
List Price:  Kz83,397.65
You save:  Kz25,021.80
CLP$66,628.33
List Price:  CLP$95,187.41
You save:  CLP$28,559.08
CN¥507.11
List Price:  CN¥724.48
You save:  CN¥217.36
RD$4,113.13
List Price:  RD$5,876.15
You save:  RD$1,763.02
DA9,393.54
List Price:  DA13,419.92
You save:  DA4,026.38
FJ$158.35
List Price:  FJ$226.22
You save:  FJ$67.87
Q545.71
List Price:  Q779.62
You save:  Q233.91
GY$14,678.83
List Price:  GY$20,970.66
You save:  GY$6,291.82
ISK kr9,808.34
List Price:  ISK kr14,012.52
You save:  ISK kr4,204.17
DH708.72
List Price:  DH1,012.51
You save:  DH303.78
L1,243.72
List Price:  L1,776.81
You save:  L533.09
ден4,025.16
List Price:  ден5,750.48
You save:  ден1,725.31
MOP$565.76
List Price:  MOP$808.27
You save:  MOP$242.50
N$1,323.80
List Price:  N$1,891.23
You save:  N$567.42
C$2,582.07
List Price:  C$3,688.83
You save:  C$1,106.76
रु9,353.99
List Price:  रु13,363.42
You save:  रु4,009.42
S/263.57
List Price:  S/376.55
You save:  S/112.97
K270.82
List Price:  K386.91
You save:  K116.08
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,859.31
List Price:  ZK2,656.27
You save:  ZK796.96
L325.94
List Price:  L465.65
You save:  L139.71
Kč1,644.39
List Price:  Kč2,349.23
You save:  Kč704.84
Ft25,663.75
List Price:  Ft36,664.08
You save:  Ft11,000.32
SEK kr762.14
List Price:  SEK kr1,088.81
You save:  SEK kr326.67
ARS$61,304.48
List Price:  ARS$87,581.58
You save:  ARS$26,277.10
Bs486.59
List Price:  Bs695.16
You save:  Bs208.56
COP$277,527.04
List Price:  COP$396,484.19
You save:  COP$118,957.15
₡35,650.64
List Price:  ₡50,931.67
You save:  ₡15,281.02
L1,732.56
List Price:  L2,475.19
You save:  L742.63
₲522,432.19
List Price:  ₲746,363.69
You save:  ₲223,931.50
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł282.07
List Price:  zł402.98
You save:  zł120.90
Already have an account? Log In

Transcript

Welcome to Lesson nine, we're going to learn a little bit more about input, processing and output using Python. Let's get started. Now we're really talking about when we talk about input processing and output is also the code and what each part of the code do. There are built in functions in Python and in every programming language that is going to do something. So a function is a piece of code that performs its duty, you're going to tell it what you wanted to do, you create the function and then that function is there because it's supposed to do that. In Python, the code block with every function is going to start with a colon So here's an example right down here, you see the arrow pointing to it, def.

Print me, an str is used as an argument, which we'll talk about in just a second. This prints a pass string into the function, print, str, and then return. So def is defining a function print me is the name of the function. And the str is the argument or the data that we're going to give that function. The string is this prints a pass string into the function. And you notice that's in quotes.

And strings must always be in quotes. We're going to talk about that a little bit more in in a minute. And then we say print str. So print is a built in command in Python, and doesn't mean it's going to print to your printer, but it does mean that it will display the output on the screen. So if the user has the program, often Running and it says this principle string into the function that's going to be the the part that they see as the user, you're not going to see the def print me or any of those lines other than what is inside the quotes, they also will not see the quotes. So the argument gives data to the function.

So when we put str in parentheses, then we're giving that data to the function. And then the statements are going to execute in order. So first, it will print string and then it will return a value. So I promised I would say a little bit more about strings. And here we are. A string is a sequence of characters.

So for an example is if you wanted to pop up on the screen Hello, how are you? That is a string. Everything that is within those quotes is considered to be in that string. In Python, it doesn't care if you use single quotes or if you use double quotes. A single quote, as you can see in the example there is where it's just the one quote, you don't have to use your shift key in order to bring up that quote. So it might be, you know, the lazy way to do it, but it still works.

And then double quotes are if you want to hit your shift key, and then hit the quotes, it'll have double quotes. Now, while Python doesn't care if you use a single quote, or a double quote, you cannot start a string with a single quote and end with a double quote, you must use the same method however you do it. And so you should buy practice, just simply use the same method whether you use a single quote or double quotes. Just use that same way every single time when you use it, and then you won't have to worry about it. Another item that you're going to use in your program is called a variable. A variable is a name that represents a value stored in computer memory.

So it represents the value. In the picture below you can see I have name equals john name is a variable. So now every time I want the value that is in that variable to show up, all I have to do Type in the variable, and then it will show. So as you can see from looking their name equal john name is my variable name, I have assigned it the value of john. So when I run the print statement and say my name is and everything I want to go on the screen is in quotes, right? But in Python, if I want to use a variable, I have to put that outside my quotes and I have to separate the quote area with the variable area with a comma.

Rules are important. If you don't follow the rules, you will have errors when you try to run your program. So a variable once again, it holds the value. We tell it to hold the name john and everywhere that I put the variable name in my program is going to give me The value that's in there. If later on in the program, I changed the name, Joe, then I go to print it out, it's going to print Joe. The cool part about this is, if you did want to change a value, you only have to change it in one place.

And then everywhere you're calling that variable is going to change the values. So you don't have to pour through thousands of lines of code to try to change every single value. That's why we use variables, it holds a spot, it's easy to change the variable, the value that is within the variable, instead of going through an entire program to change that. So it might take a little bit of practice, but name equals john. Name is the variable we have assigned it a value of john. And as you can see, when we use the print function on there, and it comes up on the screen, it will come out my name is john.

The user doesn't see print, the user doesn't see the quotes. The user doesn't see the comma or the parentheses or any of that stuff. My name is john as all the user sees. an assignment statement is another thing that you're going to be using in your program. So if you look at the picture here name equal john name as we know that is a variable, right? We just learned that the equal is called an assignment operator because it allows us to assign the value john, to the variable name.

Name equal john, all of that together is called the assignment statement. It's important to note that every time you create a variable in Python, the variable must be on the left, then the operator and then the value you're assigning the variable must be on the right side of that operator, if you try to turn it around, and if you Say john equals name, john then is actually going to become your variable. If you put it in quotes like you're supposed to, you're just going to get an error. And so that's not going to work. A variable can also be passed as an argument to a function. And you can only use a variable if it has a value assigned to it.

So if we put name as a variable, but we don't assign it any value at all, later, when we try to run the program, it's going to give us an error because there is no value in it and it's empty. Every program has rules. And in this program, there are certain rules to naming a variable there are very important to know. So, one thing you cannot do is you cannot use a Python keyword as a variable because the key word is built into the system and the program going to look at it and it's going to think that it's a command or something that it's supposed to do, instead of thinking that it's a variable. So there are lots of reserved words that can be used, but we cannot use them as variable. So far what you've learned is the death, which is defining a function and the print, which is used to print something on screen, so you only know the two but those two for sure cannot use as a variable right?

Also, you can't put spaces in your variable. For example, if we need to put two words together, maybe we have a lot of variables with the word amp in it, we have maybe an amp, ID and Name and Last Name, Address etc. We cannot put spaces between those words when we use them as variable. The first character must be a letter Or an underscore. So we cannot use a number as the first character of our variable. So it has to be a letter or an underscore.

Once you've created the first character of your variable, though, then you can use letters, digits or underscores. But the other important thing to remember is variables are case sensitive, case sensitive. So if I had capitalized the name variable, everywhere I go to call that name variable, I have to capitalize it. The name should also reflect the use. So if I'm asking for a name, and I call it name, okay, that's great. If it's an employee record, you may want to call it amp name because that tells you it's an employee name.

If it's an ID, you may want to call it amp ID because it tells you it's an employee ID and your customers are going to have a different set of IDs. So it's really important to distinguish between the two. Mostly the reason that it's important is because when you're trying to scroll down through all the different coding and stuff, it makes it very easy to visually identify. Yay, look at you. You got all the way through this lesson. See, it wasn't too bad at all.

Of course, we still have a lot more to learn. So stick around for the next lesson. See you soon.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.