Pick a number

Hello this time we are going to do a program to learn how to generate random numbers, use conditionals and a counter.

What does the program do? It picks a random integer in the range of 1 to 100 (you can do it on any other range if you want). It then prompts the user for a guess of the value, with hints of «too high» or «too low»

captura-de-pantalla-2017-02-20-a-las-11-10-43-a-m

This is the program (there are different ways to generate a random number so feel free to search others and share them). then we initialize the counter (times = 0) and we give a value to the variable of the number (tr = 0) otherwise the program fails for the condition because it does not have a value to which compare the random number. I add to the conditional that if the number of tries is more than 5 the program prints «Sorry your attempts are over».

The lines 9 and 12 are the part of the counter (times=times+1) all that can be improve, but I did it like that to be clear about what is happening.

If you still have doubts check these pages : https://docs.python.org/2/library/collections.html

https://docs.python.org/3/library/collections.html

Thats it for this post thanks for read it. 🙂

Temperature. (simple math operations and conditionals)

Hi, this time we are going to do a program to calculate the conversion  from a fahrenheit temperature to celsius and after that it should write if the water would boil or not at that temperature (under typical conditions), the formula is C = 5 ∗ (F − 32)/9 and the water at normal pressure boils at 100ºC (212 F). To do this program we must know how to do functions, do math operations and use conditionals. captura-de-pantalla-2017-02-07-a-las-4-34-59-p-m

this is my code, now lets explain the things that I think are the most the difficult, first the math operations the majority of the are like like we already know except the multiplication remember to use «*» every time because (x)(y) its a common error, no programming language recognize this as a multiplication. I already explain functions and how to print if you have doubts check my other posts just remember to use colon when you ask for a number otherwise it would look like this:

captura-de-pantalla-2017-02-07-a-las-5-09-45-p-m

we do not want that and finally conditionals.

What is an if? Its a control structure that we can use as instructions to the program in this case if the temperature on celsius is more or equal to 100 the program will print something.

What is an else? Its the complement of an if, this means that if the condition is not met the program will execute other part of the program in this case it will print other thing

this is what happens whit a temperature grater or equal to 100ºC

Captura de pantalla 2017-02-07 a las 4.34.49 p.m..png

this is what happens whit a temperature lower than that

captura-de-pantalla-2017-02-07-a-las-4-34-36-p-m

thats it for this post see you on the next one \(• ◡ •)/

 

 

#Quiz04 the return of the functions

Guess what, another quiz today whit more functions,lets start. What are we going learn on this post?, two functions one to get the minimum number and the other to get the sum of the squares of the numbers  captura-de-pantalla-2017-02-02-a-las-10-43-15-a-m

this is the my code there are different ways to do this, remember that on programming there is not a correct or wrong wat to do it, the only thing that matters is if it works and if its efficient. Having said this let me explain my functions, remember that the function its made before (on the first 5 lines of the code), and we use them later (lines 10 and 11), on the lines 7, 8 and 9 we ask the user for the numbers and finally we print the results of the functions on the line 12.

lets try program whit 9, 2 and -3 to make sure the negative numbers dont breaks  program

captura-de-pantalla-2017-02-02-a-las-10-43-03-a-m

and thats it see you next post 😀

«Fun» whit numbers

Hello, on this post we are going to learn what is a variable, how to use it and do simple math operations. First of all lets start defining the concept of variable, its basically something that keeps information, unlike a string (we learn about that on the post «Hey there and Hello world») its used to save a number value not text, whit these values we can do math operations, we use the function input() to recibe the number that the user type, there are different types of ways to save a number, as an integer, absolute value, complex, etc, to do this we specify the type whit functions i used int() for an integer number. Its necessary add the math library to do the operations, once we do this we do the math operations using the variables

what is going to be calculated:

  • 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.

captura-de-pantalla-2017-02-01-a-las-11-41-20-p-m

lets try the program whit 9 and 5

Captura de pantalla 2017-02-01 a las 11.41.03 p.m..png

and thats it, now you know how to use a variable and do basic math operations, thanks again for read my post i hope you have enjoy it 😉

Quiz3 #Quiz03

Today we had a quiz on my class of programming and im going to share my program and explain it

The program ask for a number and then print the square and cube root of that number

captura-de-pantalla-2017-01-30-a-las-9-42-25-p-m

the program use math functions to calculate the roots on the first five lines of the code, to do a functions we start defining the name (this functions names are «sqrt_root» and «cube_root» ), after that we write what do we want to do whit the value using return, to end the program we validate the number whit an if, while the number is positive the program works normally if its negative the program will write «the number its negative so the root its a complex number».

normally :

captura-de-pantalla-2017-01-30-a-las-9-44-47-p-m

negative number:

Captura de pantalla 2017-01-30 a las 9.57.36 p.m..png

thats it for now, thanks for read my post 😀

 

Hey there and «Hello world»

Hello and thank you for visit my blog, my name is Hector and this is my first time posting something like this on the internet I am a student at the ITESM (Campus Guadalajara), and i will be posting on this blog to share my few knowledge on programming, im going to use python3 as my programming lenguage for my  post  since its a very common high level language used by a lot of companies and above that its easy to learn and use . This is my first post and i wanted to do something that its a traditions for every programer the «Hello world» program, the first program created by almost everyone including me (mine was made on C#), this little program its ridiculously easy it just need a line of code captura-de-pantalla-2017-01-19-a-las-5-43-56-p-m

print() its a function of python3 (something that the language use as a system of information output) used in this case to write «Hello world» on the shell (a shell is a user interface for access to an operating system’s services), to print text in python3 and every other language it needs to be between(«double-quotes») because every text its a string (data type used in programming ). Once the program its done it most be saved as  «something.py» and try run it on the shell

captura-de-pantalla-2017-01-19-a-las-5-43-39-p-m

and thats it.

My objetive for this blog its create something of quality and not a bushleague product, thats why im posting something related to programming and not just introducing me, i hope you have learn something and i am going to end this post saying

Lets learn to program together 

helloworld

http://www.quickmeme.com/meme/35c207