mejorar el modulo random
Publicado por michel (1 intervención) el 20/08/2017 17:42:18
Tras realizas un programa en el que yo doy un numero y el ordenador tiene que adivinarlo usando numeros aleatorios. Me he dado cuenta de que las predicciones son como demasiado por asi decirlo " inteligentes" casi nunca falla . Algun consejo para que usando el modulo random sea mas "humano"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#the computer have to guess your number
import random
print("\t\t\tNOW THE COMPUTER GUESSES YOUR NUMBER")
a = int(input("what's the lowest number it could be"))
b = int(input("what's the highest number it could be"))
number = int(input("which is the number you want the computer to guess"))
maxtries = int(input("wich are the maximun tries the computer have to guess it"))
counter = 0
guess = random.randint(a,b)
while guess != number and counter < maxtries:
print("i know that it's not ", guess)
#
if guess > number:
print("that was high")
b = guess - 1
elif guess < number:
print("that was low")
a = guess + 1
#
guess = random.randint(a,b)
counter += 1
if guess == number and counter < maxtries:
print("\noooh boy, i got it",number," and in", counter,"tries")
else:
print("damn it i needed more tries")
input("\nprees the enter key to log out")
Valora esta pregunta
0