<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jose Salvatierra</title>
    <description>The latest articles on DEV Community by Jose Salvatierra (@jslvtr).</description>
    <link>https://dev.to/jslvtr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F254535%2Fa8ab31fa-3b6d-4f43-845d-45da76f9e33c.jpeg</url>
      <title>DEV Community: Jose Salvatierra</title>
      <link>https://dev.to/jslvtr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jslvtr"/>
    <language>en</language>
    <item>
      <title>Day 3 Project: A Simple Earnings Calculator</title>
      <dc:creator>Jose Salvatierra</dc:creator>
      <pubDate>Fri, 03 Apr 2020 08:05:02 +0000</pubDate>
      <link>https://dev.to/tecladocode/day-3-project-a-simple-earnings-calculator-2fn5</link>
      <guid>https://dev.to/tecladocode/day-3-project-a-simple-earnings-calculator-2fn5</guid>
      <description>&lt;p&gt;Welcome to the first mini project in the &lt;a href="https://blog.tecladocode.com/30-days-of-python/"&gt;30 Days of Python&lt;/a&gt; series. For this project we're going to be creating a simple console application that will help an employer calculate an employee's earning in a given week.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;30 Days Of Python is a free series we've been running over in our blog. Every day for 30 days we teach you something new about Python (aimed at beginners), and give you exercises. Every 3 days we have a mini project, and every 7 days a slightly larger project for you to complete!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you haven't tackled the &lt;a href="https://blog.tecladocode.com/python-30-day-3-string-formatting"&gt;rest of the day 3 content&lt;/a&gt;, I'd recommend you do that before trying the project. You can also review the previous days by clicking the link at the top of this blog post.&lt;/p&gt;

&lt;p&gt;Below you'll find a project brief, as well as a model solution with an explanation. I'd really recommend you give this a go on your own before looking at the solution; you'll get a lot more out of it, I promise. If you get stuck, there's nothing wrong with referring back to the previous posts in this series, or looking at any notes you've written. This isn't an exam!&lt;/p&gt;

&lt;p&gt;Once you've written your program, you shouldn't be worried if it looks a little bit different to ours. You might have chosen different variable names or prompts, or you might have used a slightly different approach to us. This is absolutely fine. There are often may different ways to write even very short programs like this.&lt;/p&gt;

&lt;h2&gt;
  
  
  The brief
&lt;/h2&gt;

&lt;p&gt;Our application should work as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user should be given three prompts where they'll be asked to provide different information about an employee. One prompt should ask for the employee's name, another should ask for their hourly wage, and the final one should ask how many hours the employee worked this week.&lt;/li&gt;
&lt;li&gt;The employee name should be processed to ensure that it's in a particular format. All employee names should be stripped of any excess white space, and should be in title case. This means that each word is capitalised with all other letters being lowercase.
For example, if the employer accidentally has caps lock on and they write &lt;code&gt;"rEGINA gEORGE"&lt;/code&gt;, the name will still be correctly stored as &lt;code&gt;"Regina George"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The employee's total earnings for the week should be calculated by multiplying the hours worked by their hourly wage.&lt;/li&gt;
&lt;li&gt;Remember that any user input we receive is going to be a string. While we can multiply strings, it won't quite do what you want in this case. It's also worth keeping in mind that the employee's wage, or the numbers of hours they worked, might not be a whole number.&lt;/li&gt;
&lt;li&gt;After processing the employee's name and calculating their earnings for the week, the program should output this information as a single string. For example, output like this would be appropriate:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Regina George earned $800 this week.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution walkthrough
&lt;/h2&gt;

&lt;p&gt;Below you'll find a walkthrough for how we would approach this particular problem. Once again, if yours is a little different, don't worry!&lt;/p&gt;

&lt;p&gt;We also have a video version which you can watch &lt;a href="https://youtu.be/QdUt27CuiNE"&gt;here&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;For this project, we're just going to tackle things one step at a time. It's always a good idea to break down tasks into simple chunks, because it makes projects way less intimidating.&lt;/p&gt;

&lt;p&gt;First up, we're just going to ask the user for some information. We're not going to process any of the strings, and we're not going to worry about types. We just want to get information from the user and store this information in some variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is their hourly wage? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hours_worked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many hours have they worked this week? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we want to test that things work, we can just print the variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hourly_wage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours_worked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We shouldn't have any problems at this stage, so we can move onto correcting the &lt;code&gt;name&lt;/code&gt; input. There are a few options for how we write this, but fundamentally the approaches are going to be the same. We need to call the &lt;code&gt;strip&lt;/code&gt; method to remove excess white space from both ends of the string, and we need to call &lt;code&gt;title&lt;/code&gt; to convert the string to title case.&lt;/p&gt;

&lt;p&gt;One way we could do this is to create three different variables, and perform a different operation on each line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;stripped_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;title_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stripped_name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is fine, but we don't need to use different variable names here. We're not going to use the &lt;code&gt;name&lt;/code&gt; in its raw form, so we don't need to preserve it. The same for the string we've stripped of white space. We're only concerned with the final product, so we can safely overwrite &lt;code&gt;name&lt;/code&gt; at each stage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If we want to be really succinct, we can chain various operations on the end of the &lt;code&gt;input&lt;/code&gt; call like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The reason this works, is because Python is going to evaluates each of these calls (which are all expressions) one at a time, starting from the left.&lt;/p&gt;

&lt;p&gt;So first we have the &lt;code&gt;input&lt;/code&gt; call. This is going to evaluate to a string before &lt;code&gt;strip&lt;/code&gt; is called.&lt;/p&gt;

&lt;p&gt;Let's imagine the user enters &lt;code&gt;" rEGINA gEORGE "&lt;/code&gt;, with all this white space around the actual name. This is what we get back from &lt;code&gt;input&lt;/code&gt;, so after &lt;code&gt;input&lt;/code&gt; has finished running, our line of code is roughly equivalent to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;" rEGINA gEORGE "&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the next operation to perform is the &lt;code&gt;strip&lt;/code&gt; call. &lt;code&gt;strip&lt;/code&gt; also evaluates to a new string, so we end up with something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"rEGINA gEORGE"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the white space is gone, and we have one more operation to perform: the call the &lt;code&gt;title&lt;/code&gt;. &lt;code&gt;title&lt;/code&gt;, much like &lt;code&gt;strip&lt;/code&gt; and &lt;code&gt;input&lt;/code&gt;, evaluates to another string, which leaves us with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Regina George"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that our employee's name has been properly processed we can start thinking about calculating their earnings. Unfortunately, we're not going to be able to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is their hourly wage? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hours_worked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many hours have they worked this week? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;earnings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;hours_worked&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is going to give us a &lt;code&gt;TypeError&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Traceback (most recent call last):
  File "main.py", line 5, in &amp;lt;module&amp;gt;
    earnings = hourly_wage * hours_worked
TypeError: can't multiply sequence by non-int of type 'str'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The message here is fairly clear, we're multiply a string by a string, but at least one of these needs to be an integer.&lt;/p&gt;

&lt;p&gt;Okay, so let's change the hours worked to an integer and see what happens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is their hourly wage? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hours_worked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many hours have they worked this week? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;earnings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours_worked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;earnings&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you try to run this code, you're going to get the value you entered for the hourly wage repeated a number of times equal to the value you entered for hours worked. This is because multiplying strings by an integer is a shorthand for performing a repeated string concatenation. &lt;code&gt;"-" * 5&lt;/code&gt; is the same as &lt;code&gt;"-" + "-" + "-" + "-" + "-"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With this in mind, we're going to need to convert both values to numbers. However, instead converting to integers, we're going to convert to floats, because this will allow us to accept non-integral values for the user's wage or hours worked. We want to be able to calculate 32.5 hours worked at an hourly wage of 13.50, for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is their hourly wage? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hours_worked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many hours have they worked this week? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;earnings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hourly_wage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours_worked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Make sure you print earning to check your code. If Python raises some exceptions, try to figure out why they're happening using the error message and the traceback.&lt;/p&gt;

&lt;p&gt;One thing we won't be able to do is accept a wage with a currency symbol. If you want an extra challenge, you can try to figure out how to do this for your local currency. You might want to look at the documentation for &lt;a href="https://docs.python.org/3/library/stdtypes.html#str.strip"&gt;strip&lt;/a&gt;, &lt;a href="https://docs.python.org/3/library/stdtypes.html#str.lstrip"&gt;lstrip&lt;/a&gt;, and &lt;a href="https://docs.python.org/3/library/stdtypes.html#str.rstrip"&gt;rstrip&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we've written all of our program's logic, we just need to output the information to the user. I'm going to use an f-string here, but you're more than welcome to use &lt;code&gt;format&lt;/code&gt; or string concatenation if you prefer. If you use concatenation, remember that you can only concatenate strings!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is their hourly wage? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hours_worked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many hours have they worked this week? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;earnings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hourly_wage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours_worked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"{name} earned ${earnings} this week."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With that we're done!&lt;/p&gt;

&lt;p&gt;Hopefully you were able to do this on your own, but if not, don't worry! Programming is hard, and it takes time to really absorb these new concepts. Stick with it, and make sure to review the content for the last few days if you need to.&lt;/p&gt;

&lt;p&gt;As always, you can find us on &lt;a href="https://discord.gg/BBWwyMq"&gt;Discord&lt;/a&gt; if you need any help.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus material
&lt;/h2&gt;

&lt;p&gt;One tiny issue you may notice is that we have a variable amount of precision after the decimal point when printing the employee's earnings. There are several ways we can get around this, a few of which you can find below if you're interested in digging into this a bit deeper.&lt;/p&gt;

&lt;p&gt;One option is to convert the result of our calculation to an integer. This will "truncate" the float, essentially throwing away everything after the decimal point. This certainly looks a lot better, but we're throwing away some precision.&lt;/p&gt;

&lt;p&gt;A slightly better option is to round the float, rather than just trimming off the values after the decimal point. There are some subtleties you need to be aware of when rounding in Python, but we have &lt;a href="https://blog.tecladocode.com/rounding-in-python/"&gt;a post you can read&lt;/a&gt; on this topic.&lt;/p&gt;

&lt;p&gt;A final solution to this problem involves using some a special formatting language which comes as part of Python. One of its feature will allow us to specify how many decimal places we want to display for our floats. We have &lt;a href="https://blog.tecladocode.com/python-formatting-numbers-for-printing/"&gt;a post on this topic&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;Here is what our solution would look like using these special formatting options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please enter the employee's name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;hourly_wage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What is their hourly wage? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;hours_worked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"How many hours have they worked this week? "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;earnings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hourly_wage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours_worked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"{name} earned ${earnings:.2f} this week."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's everything for today's project! I hope you enjoyed completing it, and seeing our solution as well.&lt;/p&gt;

&lt;p&gt;Follow us &lt;a href="https://twitter.com/tecladocode"&gt;on Twitter&lt;/a&gt; for more updates when we release new content for this series!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>30daysofpython</category>
      <category>learnpython</category>
      <category>python</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
