Tag Archives: #WSQ06

RANDOM_


RANDOM_

RANDOM_


DIEGO PLASCENCIA A01229988

ESTA PRACTICA ES PARA QUE EL USUARIO ADIVINE UN NUMERO ENTRE 1 Y 100 QUE SE CREA ALEATORIAMENTE, ES UN PROGRAMA MAS COMPLICADO PORQUE REQUIERE DE OTRAS LIBRERIAS ADEMAS DE LA QUE SIEMPRE USAMOS, UN COMPANERO PREVIAMENTE RECOMENDO ESTA PAGINA, YO TAMBIEN SE LAS RECOMIENDO:

http://www.marcsdev.com/2012/09/obtener-numeros-aleatorios-en-c-rand.html

ASI ES COMO QUEDO MI CODIGO:

WSQ06 – pick a number

this time the program has to pick a number at random from 1 to 100 and ask the user to gues the number, after the user makes a guess the program will give hints if the number the user gave is too high or too low in relation with the number picked by the program.

for the program to choose a number at random you can use the random function of python:

import random

and give a variable for the value, if we want a number from 1 to 100 set the range (1,101) because the range goes from the first number to the number before the last.

import random

x = random.randrange(1,101)

with that you should get a random number between 1 and 100. now ask the user for an integer to continue with the program and open a “while” loop so the program doesn’t stop until the number from the user is the same as the random:

y = int(input(“number”))

while y != x:     ——- (“!=” means not equal to)

and to give the hints to help the user use if statements and ask for anothe number:

if y > x:

   print (“too high”)

   y = int(input(“again”))

make another for a number below the random. when the user hits the number tell the program to print it:

print (“correct it is “,y)

if you want to add a counter to know how many times you tried make a variable with 0 and do this inside the while loop:

z = 0

while y != x:

    z += 1

and tell the program to print the result at the end:

print (z)

my code is in github:

https://github.com/nazare52/progra/commit/2515ed92aae442c058c6c1c325ed6bbe2a24cb0d

this video helped me to understand loops in python:

https://www.youtube.com/watch?v=9AJ0uoxtdCQ

 question- how do I tell the program to run again after completing the condition of the while loop?

pick a number!!

pick a number!!Este programa presenta un numero X entre el 0-100 y debes intentarlo adivinar!!

#WSQ06 #TC1014

pick a number!!

Pick a Number #WSQ06 #TC1014

Here is my program:

Pick a Number #WSQ06 #TC1014

 

Pick a Number #WSQ06 #TC1014

Pick a number


Pick a number

Pick a number

I had some trouble with the random number choice, so I got to this blog, may be that will help you.
http://www.cplusplus.com/reference/cstdlib/srand/

RANDOM NUMBERS!!

WSQ06

RANDOM NUMBERS!!

This program allows an user to enter random numbers in the range of 1-100, so the user has to guess a number. If the number you enter in the program isn’t the correct one you have to try more times until you guess the number, if the number you picked is too low the program will send you a message “Too low” and if the number you picked is too high the program will send you “Too high”, basically the program give you clues to guess the number, it’s like a game, have fun.

RANDOM NUMBERS!!

#WSQ06

This is a very interesting activity because you need to use conditionals, loops and different libraries.

To learn something about libraries I found this link that helped me a lot:

http://www.marcsdev.com/2012/09/obtener-numeros-aleatorios-en-c-rand.html

Here are some pictures, in the first one you find my code and he second one shows the program working.

Also, you can find my c++ code here:

https://drive.google.com/file/d/0B-NM4ghaDXBvU0ZnaUhmb1lpb1U/view?usp=sharing

Random number game

For we programmed a little sort of game. The program randomly chooses a number in the range given, and asks you to make a guess. Given the case that you input a wrong value, the program compares it to the stored random value generated before and prints a “too low” or “too high” message depending on the case. The conditional section is looped inside a while the given value is not equal to the stored value. Again, all this loop is looped inside another “Do you want to play again?” do-while loop that checks if you entered yes or no, depending.

 

This is a pic of the code I built for the most useless game in the world.

Cheers.

Note the range I defined is between 1 and 100

 

And here it is how it looks.

 

 

WSQ06

Investigué la funcion Srand en esta pagina http://www.cplusplus.com/reference/cstdlib/srand/ y así pude hacer mi programa 

WSQ06 – Choose a Number