WSQ01 – Basic output and user input (Python3)

--Originally published at Elu's Blog

These were the instructions that I was given for this assignment:

Ask the user for two integer values, then use those two values to calculate and show the following:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

After I investigated about it, I came up with this code:

Captura de pantalla 2017-01-18 a la(s) 17.09.05.png

I’m going to explain line by line this code:

Line 1: var1 = int(input(“Enter the first number: “))

var1 is the name of the variable in this line. The equal sign means that the next thing to the right is going to be the value of the variable. The int() function converts whatever is inside it into an integer (numeric value). The input() function makes it so the user can input any value. The things inside the input() function are things that will be printed before receiving any value. So this line will first print “Enter the first number: “, then the input() function will receive a value as a string. Then the int() function will convert whatever string it received to an integer. And finally it will assign that value to the var1 variable.

Line 2:  var2 = int(input(“Enter the second number: “))

This line does exactly what the one before that but it changes what it is printed on-screen and that the variable that is being assigned a value is var2, instead of var1.

Line 3: print(“The sum of the two numbers is:”,var1 + var2)

Here we see the print() function, this function allows us to literally print on-screen whatever is between the parentheses and quotation marks (“”). For example if the code is print(“Hello world”),

Captura de pantalla 2017-01-18 a la(s) 17.39.02.png
Continue reading "WSQ01 – Basic output and user input (Python3)"