00:01
Alright, so we want to use a python program to take in the input of an employee and calculate their paycheck.
00:06
So the first thing we want from the employee is their name, which will be an input, and we'll prompt them with name just so they know what they're inputting.
00:13
Next we're going to take their hourly wage, which again will be an input, so hourly wage, and i'm going to go ahead and put a dollar sign here to make sure that the employee knows that the units we're working with are dollars.
00:27
And we want this input to be a float.
00:31
The reason why is because we want to be able to do calculations with it, so we want to convert it into a number, and we want to use a float instead of an int because wages can be fractional, right? you can have an hourly wage of $9 .50.
00:50
Likewise we want to do hours worked to be a float, and input, we're going to prompt them with hours worked, and again we want this to be a float because we want it to be a number, we're doing arithmetic with it, and we want it to be a float, not an int, because you can work partial hours, right? you can work 10 hours a week and 25 minutes, which is going to be a decimal here.
01:17
Okay, now we want to take this information to print out a paycheck.
01:21
So how does a paycheck look like? well, hopefully you'll have many examples of paychecks in the future.
01:28
But first line of the paycheck usually, somewhere at the top of the paycheck will be the employer name.
01:35
And i just used the name python university because we're learning python in this problem.
01:43
And then we're going to write the name of the employee, and then you have a pay breakdown.
01:49
So you have your regular pay, and you have your overtime pay.
01:53
Now the regular pay depends on your regular rates, which is the hourly wage, your regular hours, and we'll talk about that in a bit, and your regular pay, which is just these two multiplied together.
02:05
Your overtime pay depends on your overtime rate, which is 1 .5, or 150 % of your regular rate, and your overtime hours, and again we'll talk about this in a moment, and your overtime pay, which is just these two values multiplied together.
02:19
And then finally you have a total, which is just your regular pay and your overtime pay added together.
02:25
So let's go ahead and calculate those values from the information we have in python.
02:31
Okay, so first the rates.
02:32
So i'm going to write in a comment here that we're calculating the rates, and our regular rate is just the hourly wage that was inputted, and the overtime rate is 150 % of your regular rate, or 1 .5 times your regular rate.
02:49
Good.
02:50
Next, we want to calculate the hours.
02:54
So i'm just going to create variables here, i'm going to set them to 0 for now, but this is how overtime works usually.
03:06
So your first 40 hours is going to be regular hours.
03:11
So if you didn't work all 40 hours, then all of your hours are regular hours.
03:16
Then, after you worked 40 hours, the remaining hours you worked after the first 40 hours are overtime hours.
03:26
So how do we calculate this using python? well, if the hours that you worked, the employee worked, is less than or equal to 40, then they're all regular hours.
03:38
And there are no overtime hours, so overtime hours remain 0, we'll keep that there.
03:44
Otherwise, they work more than 40 hours, your regular hours are going to be the first 40 that you worked, and then your overtime hours are the hours that the employee worked above 40 hours.
03:59
And so this is how we do that.
04:01
We use an if statement to calculate this.
04:05
Great.
04:05
Now finally, we want to calculate the pay.
04:11
So the regular pay, again, is just your regular rate, which is how much money you make per regular hour.
04:17
So we multiply that with your regular hours.
04:20
And then your overtime pay is going to be the same formula, where your overtime rate is the number, is how much money you make per overtime hours, so we multiply that by overtime hours.
04:32
And then finally, our total pay is going to be our regular pay plus our overtime pay.
04:40
Alright, so the last thing we want to do is to print out this paycheck.
04:45
So we want to print out this paycheck, and this is going to be a string.
04:49
And we're going to format this string, but bear with me.
04:52
So the beginning of the paycheck is the employer name, which for here i'm just going to say is called python university.
05:01
And then after python university, we want to add some space, so i'm going to create a new line and another new line.
05:06
So we're going to do slash n slash n, backslash n, backslash n.
05:11
And then after those two new lines, we want the name of the employee.
05:15
So to do that, we're going to do paycheck plus equals, this adds to the end of the paycheck, string, name, and then we're going to add two new lines.
05:25
Because if we look at the example here, we have a new line and then a new line.
05:30
And then here we have something that's like a table.
05:33
Alright, so the way we format a table is with a format string.
05:38
And i'll explain how to work on that, but first i'm going to decide that this column is 10 characters long.
05:45
So all of these columns are going to be 10 characters long.
05:49
So let's work with this first row.
05:51
Alright, so type is our first column, rate is our second, hours is our third, and pay is our fourth column.
05:57
Okay, so how do we make those columns in the format string? so we do again paycheck plus equals to add to the end.
06:05
And to do a format string, you're going to need the percent symbol.
06:08
And i'm going to say 10s.
06:10
So what does this mean? i'm saying that the column or the space that the string is going to take is 10 characters.
06:16
Even if it's less than 10 characters, we're going to replace it with spaces.
06:22
And s means string.
06:24
And i'm going to put a minus here.
06:26
This minus makes sure that our paycheck is left aligned.
06:31
Right.
06:32
Then i'm going to do that for four columns.
06:34
I'm going to copy and paste this four times.
06:37
And then at the end of that row, we want to make a new line.
06:40
So we're going to do slash n.
06:42
Okay.
06:43
Now to actually put in the values here, we're going to do another percent sign after this quotation mark and then parentheses.
06:52
And we're going to do the first thing we're going to input into this tuple is what we want this first percent sign to be replaced with.
07:02
And that is type...