B
B
BenderF2020-06-02 16:10:39
Python
BenderF, 2020-06-02 16:10:39

Python random numbers?

Hello !
I'm learning Python from a children's book. In general, there is a game with guessing numbers (I will give the code below)
I played with the program, it seems like everything is clear, but I wanted to modernize it a little more complicated, and I got stuck on it. The question is most likely an easy one, but for me it is difficult and I broke my whole head.
In general, in the game you need to guess the number from 1 to 99, everything is clear, everything is clear. But here's the problem, I want to make the program take the lower limit and the upper one, so to speak, randomly, choose a number between them and guess to the user.
For example, the range of numbers is also from 1 to 99, but the program itself chooses numbers from which number and to which one:
"I guessed a number from 15 to 65" - this is how the program should choose the numbers and in the interval between them guess a random number.
Does anyone have any thoughts, honestly I can’t get there myself, in programming Zero.
Here is the code:

import random
import time

secret = random.randint(1, 99)
guess = 0
tries = 0
print ("Эй на палубе! Я Ужасный пират Робертс, и у меня есть секрет!")
print ("Это число от до 99. Я дам тебе 6 попыток.")
while guess != secret and tries < 6:
    guess = int(input("Твой вариант?"))
    if guess < secret:
        print ("Это слишком мало, презренный пес!")
    elif guess > secret:
        print ("Это слишком много, сухопутная крыса!")
    tries = tries + 1
if guess == secret:
    print ("Хватит! Ты угадал мой секрет!")
else:
    print ("Попытки кончились!")
    print ("Это число ", secret)
time.sleep(10)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iddqda, 2020-06-02
@BenderF

something like this for example:

a = random.randint(1, 99)
b = random.randint(1, 99)

if a>b:
    a,b = b,a

secret = random.randint(a,b)
print (f"Это число от {a} до {b}. Я дам тебе 6 попыток.")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question