Elige un número #WSQ06

Este programa de lejos fue el más divertido de todos. Y creo con el que también aprendí más pues aprendí a usar un módulo importante: el módulo random. Esta tarea consistía en crear un código que al ejecutarlo funcionara como un juego, en el mismo tenías que encontrar el número que eligiera la máquina entre el 1 y el 100. Si no lo lograbas a la primera, bueno, podrías siempre podías intentarlo de nuevo hasta encontrar el número correcto.

Este es el código que emplee para llevar a cabo esta tarea:

fun with.png

¡Y lo explicaré un poco! En la primera línea inmediatamente después del comentario podemos darnos cuenta que existe un ‘import random‘ y esto no hace otra cosa mas que invocar un archivo incluido en la librería de Python llamado random.py este archivo es capaz de seleccionar un número al “azar” entre el rango de número que indiques, o bien, del tipo de número que indiques. Esto se denota cuando más adelante a la variable ‘correct‘ le asigno un valor de ‘random.randint(1, 100)’ este segmento de código le dice que se tendrá que elegir un número entre y el rango de elección lo indico con los números 1 al 100. Es decir, se elegirá un número entero al azar entre el 1 y el 100.

fun

Para contabilizar el número de intentos utilicé la variable ‘attempts‘ y cada vez que haya un intento fallido, este se sumará a los otros previamente utilizados.

Como siempre, el código lo adjunto en la siguiente liga como un archivo .py.

Python.svg

Casino Game

HELLO PEOPLE!! Now I’m gonna show how to make a random generator program and how to make a game out of it. First as always, GO CHECK these pages out.

http://www.cplusplus.com/doc/tutorial/introduction/

http://www.tutorialspoint.com/cplusplus/cpp_templates.htm

Here is my code, the original and the simple one respectively:

PickANumber.cpp

Game.cpp

Ohh and check out this youtuber called thenewboston. He has this great video on how to make the random number generator. So look at his video first.

And now onwards to showing my tutorial.

WSQ06 Guess my number

 

picture079
Hello user. I want to play a game.

I am thinking of a number from 1 to 100, and it is not a decimal. Guess it or Game Over!

 

 

 

 

For this WSQ06 we had to program the system to take a number from the range 1 to 100. At this case we have to use the function rand_num and make it interger with randint(1,100) . The main point at this program is to play the “warm or cold” game where you give the player the clue that his guess was higher or lower than the actual number.

This is were one uses the conditionals if and elif, so one predicts all the possible answers from the user. If guess is higher than random number then it prints that the guess is higher. And viceverse if the number is lower.

At first I had troubles printing the “You win!” screen message.
randomnum question

Then I noticed that the last “elif” has to be written as “else” since it is the last option from the conditionals. This is without the actual condition “==”. Also, there was a problem with the indent since “else” has to match the “while” position. Like this:

wsq06 win.png

I did not used a conditional if the user tries a number higher than 100. This is because the program will tell the user to try a lower number. Everything is ready to go. Now let’s play!

wsq06 win

The WSQ06 is over, but I challenge myself to learn how to tell the user’s tries and to limit the game to an actual number of tries. This is in order to make a “Game Over” screen possible.

Today’s blog corresponds to the song “Swing Life Away” by Rise Against. No,  not Rage Against the Machine but Rise Against.  A song

swing life away

Continue reading “WSQ06 Guess my number”

WSQ #06

That page cplusplus.com is really helpful. I had to search there for the use and application of the random command. You have to set the <time.h> library so the pc won’t repeat the numbers and  set the time to NULL, this took me a while to figure out cause I was setting it to 0 and the program wasn’t compiling. So, here are the pics of the code (quite long, this one):

wsq06 code

And the exe:

wsq06 exe

I think this is gonna be it for the day, I have so much more stuff to do but I gotta work on something else right now. Thanks for reading.

“Life begins at the end of your comfort zone”

#WSQ06, PROGRAMA PARA GENERAR UN NUMERO RANDOM

randomprogramm
Así queda el programa del numero random, como podemos ver, se agregan dos librerias más, #include y #include la primera se usa para poder poner lo del numero random y que se pueda ejecturar en le porgrama, sin esa libreria, no se pueden usar esas funciones y el numero random no se generaría y la segunda libreria es para el tiempo que tarde en generarse ese numero, de nuevo, sin esa libreria, no podrías hacerlo. , los if y else son pensando en que puedes dar tanto numeros mayores al que te da el programa, como menores o hasta que des el numero igual y recordemos que lo que dice “cout”, dentro de cada if, es lo que se imprimira si dicha acción ocurre, los if’s y else’s estan dentro de un do-while, porque? pues no podria ser dentro de un for porque no sabes cuantas veces se repetira, no sabes cuantas veces te equibocaras o acertaras, solo sabes que es un ciclo que se repetira hasta que aciertes en la respuesta!(:
randompequeño
Este programa del numero random, vemos que se imprimen las intrucciones sobre lo que pusiste en el programa para que el usuario pueda comprender mejor, entonces, como vemos, en la parte de arriba se imprime esto: “numero random: 52”, este numero, no debe aparecer, puesto que tu debes adivinarlo, osea, la computadora debe generarlo, pero no imprimirse, pero para probar que funciona lo mejor es probar con que te aparezca, entonces como vemos te pregunta el numero que tu estes pensando del 1 al 100 y pones por ejemplo como ahí, el 23 y se imprime que es más pequeño, y vemos.. que es cierto.
randomgrande
Ahora, vemos que para seguir probando, como puedes ver, el programa te dio un nuevo numero (pues es al azar, recuerda), entonces

randomigual
randomreal
rara

Continue reading “#WSQ06, PROGRAMA PARA GENERAR UN NUMERO RANDOM”

#WSQ06 Pick a number. Playing on C++.

game

Hi people. I made a new program on C++ and it’s so cool. I like to do this stuff because is funny and also you learn new commands and variables that are useful on C++. On this game, you have to guess a number between 1-100. Check it and enjoy it!

 

Well, this program made me feel crazy because I didn’t know how to use a random function, but vualá, I checked a friend’s post and it helped me a lot! I searched for information on Sergio post and I found the formula and I saw the video and the pages that he used (https://sercho93.wordpress.com/2016/01/31/pick-a-number/).

And here is the screenshot of my code.

Haga click para ver el pase de diapositivas.

And the screenshot of the program running.

gpckan

On this program, we start using conditionals and cycles on C++. For the cycles, we use the commands DO-WHILE and that repeat an action until it’s false (When the While condition is false). So here, we want to find a random number between 1-100 and to make that, we use the do-while with the condition (number that the user choose != –different of– the number that the program choose), so when the function is true (different) it will repeat the program until you guess the program and the number is the same.

Also we have to use counters, to know how many guesses you need to get the correct number. To print the message of it is to low or to high, we use the conditional IF(that helps you to choose one or another way into the program, because if one it’s false, the another it’s true and with that you can take more than one way).

Another important thing is that the number has to be

maxresdefault

Continue reading “#WSQ06 Pick a number. Playing on C++.”