Tag Archives: #WSQ06

Sum in the middle of 2 numbers.

This a program to find the sum betwen 2 numbers, no of 2 intiger numbers. So if you want to see my code you can see it: https://github.com/A01229754/Tc107/blob/master/sumnum.cpp

WSQ06 Pick a Number

 

This finally function……

WSQ06

#WSQ06

En esta ocasión tuvimos que hacer un programa que diera un numero random y el usuario tiene que adivinar cual es. Para hacer esto utilice un do-while y limite el número de intentos para lograrlo con un contador. Al no haber hecho esto en este lenguaje, le pedí ayuda a un amigo que me explico muy bien como lograrlo.

Aquí se encuentra mi código:

https://github.com/JuanPabloGonzalezHuezzo/WSQ06/blob/master/Wsq06

 

#WSQ06 #TC1014

Random number (Loops and Modules)

This program calculates a random number, and asks the user to guess it by using the bisection method. This means it tells you if your guess is higher or lower. 

The source code is the following:

Number

from random import randrange

number=randrange(1,101)

counter=0

guess=0

while(guess!=number):

    guess=int(input(“Try to guess a number between 1 and 100 “))

    counter=counter+1

    if(guess<number):

        print(“Higher”)

    elif(guess>number):

        print(“Lower”)

 

print(“Correct “,number)

print(“You did in the try number “,counter)

 

First of all in order to generate the random number we find that there is a module named Random, which description we can find in the Python3 Documentation. So the first thing I did was searching information about Modules and how to import functions of them in my own program.

So the first line is used to import the randrange function from the random Module, wich gives us pseudo random numbers (random numbers are virtually impossible to get) between a  given interval without including the borders, that’s why the 101, and we asign the given number in the variable number.

Then I assigned a variable counter that is adding the number of tries the user has done to guess the number. And then I assigned the guess the value of 0, the reason is to initalize the guess as a number that isn’t in the range of the pseudo number generator.

The next step in the program is the part when the user is making several guesses to say the number the computer generated. And when we have a task that is reppeated without us knowing how many times it will be done we need to use the while loop.

You can find more information about loops in this page. The while loop is used to execute a task while the expression being evaluated proves to be false. Once the condition is proven true the program exits the loop and continues with the code below.

The other addition I did to my program is the elif command. This one is used to nest to ifs together, this means you can evaluate two different expression before an else.

In the end when the user introduces the number that the computer generated it goes out of the loop and print the number that was the answer, and right after it prints the value of the counter used for the number of tries.

This is for my of my .

 

Learn To Program 2015-02-16 22:02:00

WSQ06
Las utilización de módulos creados por default en Python son básicos para hacer programas, que si se realizaran desde cero, tendrían un código muy extenso y difícil de realizar. Basta con importar un modulo a nuestro programa principal y utilizar de manera correcta las funciones con que cuenta ese modulo.

Yo utilicé la información que muestra la siguiente pagina oficial de Python para utilizar el modulo random y crear un programa bastante especial, el cual, invito a que ejecuten. https://docs.python.org/2/library/random.html

**********************
Programa hecho en Python:
**********************
https://gist.githubusercontent.com/A01630323/ea4abd333b37786521fb/raw/9d06b91d09ab387340428aee01faccd3b5c92513/WSQ06

Learn To Program 2015-02-16 22:02:00

WSQ06
Las utilización de módulos creados por default en Python son básicos para hacer programas, que si se realizaran desde cero, tendrían un código muy extenso y difícil de realizar. Basta con importar un modulo a nuestro programa principal y utilizar de manera correcta las funciones con que cuenta ese modulo.

Yo utilicé la información que muestra la siguiente pagina oficial de Python para utilizar el modulo random y crear un programa bastante especial, el cual, invito a que ejecuten. https://docs.python.org/2/library/random.html

**********************
Programa hecho en Python:
**********************
https://gist.githubusercontent.com/A01630323/ea4abd333b37786521fb/raw/9d06b91d09ab387340428aee01faccd3b5c92513/WSQ06

Pick a Number

I made a program that asks you to guess a random number between 1 and 100. It also tells you how many tries you needed to guess it!

#WSQ06