Input, Process, Output

Introduction to Programming Input, Process, Output
15 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
€66.45
List Price:  €94.93
You save:  €28.48
£55.32
List Price:  £79.03
You save:  £23.71
CA$98.04
List Price:  CA$140.06
You save:  CA$42.02
A$107.72
List Price:  A$153.89
You save:  A$46.17
S$94.09
List Price:  S$134.42
You save:  S$40.33
HK$544.68
List Price:  HK$778.15
You save:  HK$233.46
CHF 61.92
List Price:  CHF 88.46
You save:  CHF 26.54
NOK kr774.79
List Price:  NOK kr1,106.89
You save:  NOK kr332.10
DKK kr495.67
List Price:  DKK kr708.13
You save:  DKK kr212.46
NZ$118.82
List Price:  NZ$169.76
You save:  NZ$50.93
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,339.40
List Price:  ৳11,913.94
You save:  ৳3,574.54
₹5,914.23
List Price:  ₹8,449.26
You save:  ₹2,535.03
RM311.24
List Price:  RM444.65
You save:  RM133.41
₦118,083.62
List Price:  ₦168,698.12
You save:  ₦50,614.50
₨19,391.36
List Price:  ₨27,703.14
You save:  ₨8,311.77
฿2,410.17
List Price:  ฿3,443.25
You save:  ฿1,033.08
₺2,423.71
List Price:  ₺3,462.60
You save:  ₺1,038.88
B$418.75
List Price:  B$598.25
You save:  B$179.49
R1,273.04
List Price:  R1,818.71
You save:  R545.66
Лв129.87
List Price:  Лв185.54
You save:  Лв55.66
₩97,732.12
List Price:  ₩139,623.30
You save:  ₩41,891.18
₪255.55
List Price:  ₪365.09
You save:  ₪109.53
₱4,110.61
List Price:  ₱5,872.56
You save:  ₱1,761.94
¥10,630.43
List Price:  ¥15,186.98
You save:  ¥4,556.55
MX$1,418.07
List Price:  MX$2,025.91
You save:  MX$607.83
QR254.36
List Price:  QR363.39
You save:  QR109.02
P953.37
List Price:  P1,362.02
You save:  P408.64
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,478.89
List Price:  E£4,970.06
You save:  E£1,491.16
ብር8,820.94
List Price:  ብር12,601.88
You save:  ብር3,780.94
Kz63,759.63
List Price:  Kz91,089.09
You save:  Kz27,329.46
CLP$68,404.72
List Price:  CLP$97,725.22
You save:  CLP$29,320.50
CN¥507.53
List Price:  CN¥725.08
You save:  CN¥217.54
RD$4,206.74
List Price:  RD$6,009.89
You save:  RD$1,803.14
DA9,351.13
List Price:  DA13,359.34
You save:  DA4,008.20
FJ$158.85
List Price:  FJ$226.94
You save:  FJ$68.09
Q538.41
List Price:  Q769.20
You save:  Q230.78
GY$14,600.65
List Price:  GY$20,858.96
You save:  GY$6,258.31
ISK kr9,615.92
List Price:  ISK kr13,737.62
You save:  ISK kr4,121.70
DH699.24
List Price:  DH998.96
You save:  DH299.72
L1,281.52
List Price:  L1,830.82
You save:  L549.30
ден4,084.06
List Price:  ден5,834.63
You save:  ден1,750.56
MOP$559.24
List Price:  MOP$798.95
You save:  MOP$239.71
N$1,266.15
List Price:  N$1,808.86
You save:  N$542.71
C$2,568.06
List Price:  C$3,668.81
You save:  C$1,100.75
रु9,427.87
List Price:  रु13,468.97
You save:  रु4,041.09
S/262.66
List Price:  S/375.25
You save:  S/112.58
K281.39
List Price:  K402.01
You save:  K120.61
SAR262.91
List Price:  SAR375.60
You save:  SAR112.69
ZK1,903.42
List Price:  ZK2,719.29
You save:  ZK815.86
L330.70
List Price:  L472.45
You save:  L141.75
Kč1,679.39
List Price:  Kč2,399.23
You save:  Kč719.84
Ft27,552.80
List Price:  Ft39,362.83
You save:  Ft11,810.03
SEK kr765.72
List Price:  SEK kr1,093.94
You save:  SEK kr328.21
ARS$70,549.59
List Price:  ARS$100,789.45
You save:  ARS$30,239.85
Bs482.26
List Price:  Bs688.98
You save:  Bs206.71
COP$307,907.55
List Price:  COP$439,886.78
You save:  COP$131,979.23
₡35,643.95
List Price:  ₡50,922.11
You save:  ₡15,278.16
L1,765.02
List Price:  L2,521.57
You save:  L756.54
₲545,488.80
List Price:  ₲779,303.12
You save:  ₲233,814.31
$U2,997.83
List Price:  $U4,282.79
You save:  $U1,284.96
zł286.31
List Price:  zł409.03
You save:  zł122.72
Already have an account? Log In

Transcript

Welcome to Lesson 12. We have covered now on how a program works, input and output. Remember, we always need processing as well. First is the input, then the processing, and then the output. And so now we want to talk about the processing and all the different things that are involved in the processing. Okay, so we already talked about a variable what a variable is, do you remember that a variable is a value, so it's a placeholder, we can name a variable, and our program is going to save some space in memory for what value we want to put inside that variable.

So when we use a variable, we have to use it properly. And according to our syntax and our rules for whatever type of program, we're Writing, it doesn't matter if you're writing C sharp or Visual Basic or Java or Python, we use variables and everything. So variables must have an assignment statement. For example. Say we want to know something to do with a year we're figuring out maybe how old somebody is. And so year is our variable.

And we're going to set that variable to 2016. We cannot use a variable in a program, if we don't set a value to it, it will be unusable. So, common practices. Before you start using that variable, you're going to declare the variable, meaning you're going to use a statement like this that says your equal 2013. And you're going to instantiate the variable meaning that we've given it a value of 2016. So we declare the variable year, it would probably be an int data type, right?

And we're going to set that value at 2016. It's very important to remember, a variable only holds one value at a time, that value can change throughout the program. However, you know, maybe next year, it'll be 2017. And we want to change it to 2017. And we might even have in our program, a question that says, What year is it, and then the user is going to put in there what year it is, and so that value can change from 216 2016 to 2017. But initially in the program, we're going to give it a value of 2016 so that we can do something with it during the program.

So we always give our variables a value. Something else you're going to need to do when you're processing is calculations. We can't figure out how old you are, unless we subtract the current year from your birth year. Correct. That's a calculation. So we're going to use symbols in our program.

And these symbols are directly related to Python, they will change, or they can change based on the program that you're using. The specific symbol that I'm looking at is the mod symbol, which will change. The addition seems to be consistent throughout every programming language that I've done. I haven't done them all though, so you know, just keep that in mind. So the plus is the addition operator, it's going to add two numbers together. The subtract sign is a subtraction operator and it subtracts one number from another.

The asterik is a multiplication sign and it multiplies one number by another Keep that in mind. This is the Ford slash and not the backslash, because a backslash the top of the slashes leaning backwards in a Ford slash the top of the slashes leaning forward. So note that difference if I say forward slash and must be a slash, where the top is leaning forward, if I say backslash, then that means the top of the slashes leaning backwards. So the forward slashes the division operator and it divides one number by another another, and it gives the quotient. Now the modulus is if you've ever divided anything, and there is a remainder leftover, right? That's what the modulus operator does.

And it doesn't give you the main number plus the remainder it only gives you the remainder. So we have to remember that if five is divided by two, you know two can go into five two times but there's one remainder leftover if you use the meid, you're only going to get the answer one, you're not going to get the answer to at all because it only gives you the remainder. And then we have the exponent. And of course, the exponent, raises it to a power, B must use that little carrot symbol and it is on your keyboard. From my keyboard, I have to hold the Shift down and push the number six, that's where my exponent is. Okay, so I wanted to give you an example of performing in a calculation and kind of what that looks like.

So suppose that we're going to calculate a discount for a sale. I know I love I love my sales, and I love my discount. So this is a good one to cover. We will use a combination of these variables and math expressions to calculate a value. So over here we're writing in pseudocode. Now remember writing in pseudocode Using flowcharts, this is so incredibly important.

Sure, you can write a small program that says hello world. And you can do that without writing pseudocode. Or without writing, or having a flowchart or any any way at all, you can just sit down and start putting the code in. But when you start getting in larger programs, you may lose logic and have logic errors. And so what that means is, maybe if we're trying to calculate this discount, we might not include our discount, because maybe we don't put things in logical order. I hope that makes sense.

Because we have to say that we have the price minus the discount to get the sale. If we miss that line, then they're going to pay full price and not going to get their discount and then they're going to be angry. I know I would be because I need my discounts. So in this example, we're going To calculate this discount for a sale, and so in pseudocode, we're going to say set price equals to 100. So what we're doing here is we're saying we're going to use this variable called price. And we're going to set that value equal to 100.

So whatever it is rewind, it costs $100. Then we're going to say set discount equal to 20. So in this case, our discount is going to be 20 off. Now, this is a simple example here. In most cases, you're going to put point to zero, right? Because you don't want to give them a 200 or 2,000% discount or whatever.

You have to make sure to put a decimal.to zero and then that would really be 20%. Okay, so set sail so there's another variable equal to price look, we're using a variable price. minus another variable discount? Yes. Because what does that mean? What does that mean?

That means that there is a value in this variable. And so we can say this variable minus this variable, just subtract the values that are in them. That makes it so easy, because we don't have to go and try to find that value every single time, we just use the variable. And then we're going to display the total cost is with $1, sign, comma, sale. Because we're again, we're writing this in English. This is the pseudocode example.

Or to the right here, I have a Python code example. This is what it looks like when you write in Python code. You could say price equals 100. Discount equals 20. Sale equals price minus discount, and then we're going to use the print function and say the total cost is and sale. So if you're looking at the print function, you notice that Whatever you have to print must be in parentheses.

It must be also in quotes. And what we want to display to the user. You can see it highlighted in green there, it must be in quotes. But when we add a variable, and we want to also print a variable value, we have to put a comma after our quotes to separate that. And then we put the word sale. Now in some languages, you may need to use the plus sign rather than a comma.

So just keep that in mind rules, rules, rules, rules, every programming language has its own rules. And that's one reason why you have to learn all this base information before you even get started programming. So the total cost is with the dollar sign, we have to enclose that in quotes because we want that coming up to come up on the screen. And then we put comma to separate it so that the compiler knows that we have a variable there is a compiler knows that we have a variable there is not going to print the word sale to the user is going to print what the actual sale price is. And user is not going to see the print statement, users not going to see the parentheses or the quotation marks or any of that stuff, okay? It's just going to come out the total cost is there'll be $1 sign there, because we included that in our parentheses, and then whatever value is in sale is going to show.

Okay, so I know this isn't a math class, but you've got to keep in mind that if you're going to do some programming, you may have to do some math, it's very important. We can't calculate a paycheck. If we don't do some math, we can't calculate the discount. If we don't do some math. We can't calculate an age if we don't do some math. So there are a lot of ways where if you want to program you don't have to do a lot of Heavy math programming, you just need to know, you know, add, subtract, multiply, divide margin listen in some of the main ones.

But if you go into anything like for accountants or for if you're if you're programming for gaming or anything like that, and that becomes very, very math heavy. So you're going to need that as well if that's what you want to do. So we had to talk about the order of operations. And it's not always the same in every language, you some of them go right along with the math rules that we learn when we're when we're taking math and some of them are rules based on that particular programming language. They're all very close. But make sure you pay attention to those rules because they do change slightly, depending on the language that you're using.

So with Python, the order of operations is parentheses. exponents, then multiplication division or modulus from left to right, then add and subtract, which is also left to right. Your parentheses you can use to change the the order of what things run because parentheses always run first, so you can choose where to put the parentheses. So I have an example here, if we say five plus two times four equals 13, there's no parentheses there. So the first thing that would run would be the multiply, divide. modulus number three, and then they add, subtract, so you would have to multiply two times four, which is eight, and then add the five, which makes it 13.

But if you really wanted the five plus two to add first, you could put parentheses around five plus two and then that's going to happen first, so five plus two equals seven, and then we multiply that by four and it becomes 28. So because of the huge number difference here, you can see the same numbers are being used, but one sum is 13. And the other son is 28. So it's extremely important to pay attention to your order of operations. Whenever you have calculations, the best thing that you can do is just double check your calculations to make sure that they are coming out with the correct answer. So that way, you know that the math is running properly.

You always want to double check, even if you don't know the math that well and you say I'm just going to use a spreadsheet and then I'm going to, you know, maybe you know how to use spreadsheets and put formulas in there. And you want to check it that way. That's fine. Any way that you want to check it and check it with a calculator, whatever it is that you have to do, but you want to make sure that it's coming out correctly, because that is a huge, huge, huge mistake. Okay? And if you're calculating somebody's paychecks, that's not a mistake that you want to make.

Yay, we successfully completed processing calculations Way to go, Don't you just love these little small lessons, you can look at them over and over and over again if you want to, and really, really get it in your brain. I love that too. You have access to the videos and you can just listen to them over and over again. And I highly recommend that you do. These are not concepts that just anybody can get right off the top. I mean, there are a few prodigies that were just born to program.

But programming is a struggle for many, many people. And we have to learn logic first, or it's a superduper struggle. So this is why I did the intro to programming class, we have to learn the logic first. Once you learn the things that you're going to learn in this class, you'll be able to go do any programming language because it's important to understand how variables work it's important to understand how to perform calculations, it's important to understand how assignments work. And so once you know that though every language is just syntax and rules after that, of course, that's the most annoying part. Which is one reason why Python is such a great program to look to practice with, because you can definitely get some errors, it gets cranky and a few things.

And so that gives you some practice with your syntax. So, again, way to go. Good job completing lesson 12 and I will see you in the next lesson.

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.