WSQ01

--Originally published at Tomas Enciso

Never in my life have a written a blog post so here it goes.

For the first post im gonna show a program I had to write that basically is a simple calculator and asks for your name, using inputs, outputs and some other fun stuff.

first of I started by printing “please enter your name” followed by an input that allows the user to enter his or her name. After that, this person will be greeted by hello (and the user’s name).

Using variables I was able to let the user choose two numbers and you would get the sum, subtraction, multiplication, the division with no decimals and the residue or the decimals of the previous division.

This is the code that I wrote:

print(“please enter your name”);
name = input(“”)
print(“Hello”,name)
x = int(input(“Please enter a number “))
y = int(input(“Now enter a different number “))
print(“If you sum these two numbers you get “,x + y)
print(“The subtraction of this two numbers is “,x – y)
print(“The multiplication of “, x, “and”, y, “is”,x * y)
print(“If you really want to know the division between”, x , “and”, y , “its”, x//y , “I guess…”) # no decimals included
print(“The remainder of this division is “, x % y, “im done, please make it stop”)

and here’s when you run it:

Tomass-MacBook-Pro-2:tecgda TomasEnciso$ python3 WSQ01.py

please enter your name

Tomas

Hello Tomas

Please enter a number 10

Now enter a different number 5

If you sum these two numbers you get  15

The subtraction of this two numbers is  5

The multiplication of  10 and 5 is 50

If you really want to know the division between 10 and 5 its 2 I guess…

The remainder of this division is  0 im done, please make it

Continue reading "WSQ01"

WSQ01

--Originally published at Site Title

Calculadora Simple:

En este post veremos el proceso para la elaboración de una calculadora simple y su uso.

Creando la calculadora

captura-de-pantalla-60

Como podemos ver esta calculadora es bastante simple. Usamos “Print” para que muestre el contenido en pantalla (dicho contenido debe estar dentro de paréntesis y con comillas), y para crear una variable, escribimos primero su nombre “num1” seguido de un “=”, en dónde el contenido que siga del igual será la variable. Cómo en este caso hablamos de un Entero colocamos “int”, seguido de un “input” para que el valor del entero lo de el usuario.

Tras pedir otro número para poder realizar la operación, ahora desplegaremos los resultados. En este caso escribimos primero la frase, y dentro del paréntesis pero déspues de las comillas y una coma, escribimos la operación según sea la que necesitemos (num1 + num2, num1 – num2, etc.)

Ahora lo ejecutamos en Python.

captura-de-pantalla-61

Ya quedó, una calculadora realmente simple. Ahora se mejorará un poco para tratar de hacerla más funcional.

captura-de-pantalla-62 captura-de-pantalla-63

Ahora desplegamos un pequeño menú con un while para que el usuario pueda realizar sus opeaciones cuantas veces quiera.Contiene también un botón de salida y le añadimos la función de potencia. Tambien le añadimos una opción para que el programa vuelva a empezar si el usuario no teclea una de las opciones que se le muestra.

Cómo se ve en Python:

captura-de-pantalla-64

Realizar calculadoras es bastante positivo para aquel que apenas va empezando a programar en un determinado lenguaje, ya que le ayuda a comprender la sintaxis y uso de varias herramientas simples tales como el int, while, if etc.

Para realizar este programa aprendí mediante este canal de Youtube: https://www.youtube.com/channel/UCLXRGxAzeaLDGaOphqapzmg

 

 


Fun with numbers

--Originally published at Programming

We are going to create a programm that first ask the user for two integer values and then, with these two numbers, calculate the sum, the difference, the product, the division (no decimal point) and the remainder of the division.

Here is the code and how it runs:

captura-de-pantalla-2017-01-21-a-las-20-47-33

Now, let’s explain how it works.

First, we need the two variables as numbers. We have to ask the user for them, so we write a String to display a message. We write the name that we want to give them to identify (for example here, num1 and num2). After that, the symbol = to assign a value and the int() function, because if we forget it, the programm will take it as a String and we couldn’t make math operations with that inputs.

Then, we declarate all the math operations we will perform. The symbols we use are + for sum, – for subtration, * for multiplication, / for division and % for the remainder of the division (the first number between the second). Notice that we have doble // in division, it is because we don’t want decimal points. You could skip this step and just write the operation in the result you are going to print, but I prefer this way.

Finally, we write print() and a String inside quotes, after that a coma and the name of the variable we already done.

And that’s it, now you can run and try your programm. Hope it helps ?

 

If you have doubts about math operations I recommend you this video: Python Programming 1: Maths Operators, and if you want a different explanation of what we did, you could watch this: Python Zero to Hero Lesson 2 variables.

 

 

 


Fun with numbers!

--Originally published at Python learning

Here I am going to show a program that asks the user for two numbers (integers) and then displays the sum, difference, multiplication, division (with no decimals) and remainder of these numbers. In this program you will be able to identify the inputs and outputs, which I already talked about and explained in a previous blog.

The code for this is as follows:numbers

And it runs like this:

numbers-running

So here, the inputs are 12 and 10, and the outputs are 22, 2, 120, 1 and 2.


Fun with Numbers

--Originally published at My programming class blog

FUN WITH NUMBERS

For our first project in python 3 we were asked to create a not so sophisticated code that asks for two numbers and automatically gives the sum, difference, product, division, and modulus operator of both numbers.

I´ll give a small explanation on what I did to make this code work and also I´ll share the sources where I found very useful information.

1.-First you must create a new project on the text editor, name it as you wish and remember to type ".py" at the end of the file´s name.



2.- Now that you have opened your text editor, start by declaring variables and making the code ask the numbers the user wants to use. For this, first give the variable a value which has to have the input function so that it lets you type a number o anything in the computer´s terminal.(you can find some more info on how to use the input function in the interactive book "How to think like a computer scientist", it explains every detail of the function in chapter 2.)

3.- It is important that if you want to use decimal numbers, you must use the float function in the next line of your code, just like this:
x= input ("Write a number")
x=float (x)

4.- Now that you´ve done the same thing for the "y" variable, you must declare a third variable which will be related to the answer to de x+y operation. Also remember that if your´re using decimal numbers and you want an exact result of the sum you must keep using the float function.
n= (x + y)
n= float (n)

5.- The 5th step will be to show the result or in other words, print it on the computer´s terminal. This has to be done with the print function.
Continue reading "Fun with Numbers"

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)"

Bash Shell.

--Originally published at マルコ

The Bash is the interface between the user and the operating system.

This program acts as an intermediary between the operating system and the user thanks to command lines introduced by the latter. Its function is to read the command line, interpret its meaning, carry out the command and then throw the result through the outputs.

 


WSQ01 – First resolution ever

--Originally published at Stuff about Python

Hi there,

So we were given the following instructions for this first little problem :

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

Which I answered with the following (quite long) bit of code, which is a bit more than necessary I assume. wsq01

So the initial idea behind the assignment was to cover basic user input (asking for 2 numbers) along with basic output (printing the results of the operations).

The user input is dealt with with the built-in function in Python 3, input(), which will wait for the user to give a value to continue. You can actually add some text to it to let the user know what you’re expecting from him. Here I asked on line 2 and 3 to enter a “First value” and a “Second value”.

I performed operations on those values, such as adding, substracting, multiplying and dividing them, as required in the instructions, and used the print() function to display them to the screen.

To perform all of this, I created a get_results() function, which allows me to use all this code anytime I want later on, without having to re-type the whole thing.

The thing that bothered me though, was that if you entered something else than an integer when asked for a value, you would just crash the program because it wouldn’t be able to perform all the operations. Yeah, you can’t really substract a “cat” and a “zebra”. So what I did about it is I created another function

Continue reading "WSQ01 – First resolution ever"

First Code Python3, about me and how to use Atom.

--Originally published at Site Title

First of all I have never used a blog so I may learn a thing or two while blogging. Also I would like to mention that I have never used terminal for writing codes and I have no idea of how the language but I’m willing to learn because I have always been a fan of Jailbreak and video games so it really doesn’t matter if I have oversleep while studying.

Atom is the program that we will use and I watched this video to learn the basics. screen-shot-2017-01-16-at-9-55-06-am

It is a series tutorial on how to use atom and change the preferences to make it more simplified and easier to use.

After watching the videos and making my research I finally could run the code that was written on Atom and run it on Terminal.

screen-shot-2017-01-16-at-9-51-34-am

My hobbies is play video games and watch F1. I’m willing to learn about coding and I want to learn more about the language and be part of the world of coding specially JailBreak. I’m still waiting for the Jailbreak for iOS 10.2