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
€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 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.