The goal is to create a program that asks the user for two numbers and Python will show the difference between them.
First of all, we need to know the keywords that we’ll use. I write this at the beginning because I had no freaking idea about which labels would make what I wanted:
print: Print is the keyword that will order Python to write an specific sentence on the editor, so the user can understand what we want him/her to do. The syntax should be lije this example: print (“Text that you want to print”)
input: This label will keep the information that we’re asking for. The syntax will be like this: input (“What we’re asking the user to write”)
float: For this program, “float” helped me to make the difference between the inputs. I’ll show you what I’m talking about when I show you my program.
The difference of the two numbers.
Ok, now, if we want to make the difference of two numbers, we need to ask for them, but also to assign a variable to each one, so then we can make the operations.
To get that, we assign a different variable to each input, like in the image below
To get the result, we just need to add another variable and assign it the value of the difference.
But be careful, THIS is why you need the floats.
If you just type (+) the program will print the first number followed by the second one, but if you write “float” before each one, you’ll get this
I figured out that a float was needed thanks to this post.
This YouTube video was helpful too.
The product of the two numbers
We keep going and make exactly the same process, but this time, instead (-), we type
Continue reading “Fun With Numbers (WSQ03)” →