In this WSQ the program will pick a number between 1 and 100 and you will choose a number between them and you need to choose the correct number to win.
This is the code of the program.
This is the program running in Cygwin.
Fundamentals and Solutions. Together!
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:
¡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.
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.
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:
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.
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.
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:
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!
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
I had a little problem with this WSQ. I didn´t knew how to generate a random number on Python. So I looked on the Internet and found this link:
https://docs.python.org/2/library/random.html
Here is my code:
And here is an example run:
🙂 🙂
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):
And the 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”
This program is to guees a random number between 1-100, it ask to give a number and until you guees the number the program will end.
Here is the program in Atom
And here is how the program works
Had just a little probles with the if part but searching in the internet and in lynda.com videos I founded how to use them in a proper way (:
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.
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