mardi 28 septembre 2021

Is there a way to make a random variable into one that isn't random?

I am experimenting and studying a lot about programming lately. I want to write a guessing game in python, where the pc guesses a number in a range defined by the user. The way I have written this part is like so:

low = int(input("Choose the smaller number: "))
high = int(input("Choose the higher number: "))
num = random.randint(low, high)
pc_guess = input("Is this number correct: "+ str(num)+ "?")

If the answer isn't correct the computer will ask if their guess was high or low. What I wanted to do, was set a new range based on the computer's guess (for example, if the guess was too high, the new ceiling would be the guess minus 1). The guessing game concept isn't new to me, I wanted to try and write it more dynamically, test myself. But I realized I didn't know the answer to this question, is there any way to take the value of a previous random number, and assign it to a variable that isn't random?




Aucun commentaire:

Enregistrer un commentaire