简体   繁体   中英

How to print out the same returned value of a Random.Randint() function

I would like some assistance in figuring out a way to print out the same number that was generated by a Random.randint() function. I first assigned the value to a variable, like so:

randomPersuade = random.randint(200,5000)

The problem is that now I have to print out the same value that was returned from this function twice in 2 different print statements

userDecide2=input("Since you decided to keep the box, I will offer you" ,randomPersuade, "for the box.\nYes to keep and No to collect the cash amount")

and

print("You decided to collect the cash amount of", randomPersuade, "Enjoy!")

How would I adjust it that I print out the same value twice, and later I would have to generate a few other sets of random integers and do the same thing, would I have to create another RandomPersuade(2,3,4,5 etc)? Won't the function generate a new value for the 2nd print statement? I would test this out myself but I would have to complete the rest of the code before I can do so, which will take a while. Any help that can be given will be much appreciated, thanks!

As you have already assigned a value for the variable randomPersuade = random.randint(200,5000) its value won't change unless you do randomPersuade = random.randint(200,5000) again.

Till then, the value for the variable remains unchanged, and you can use it multiple times without its value being changed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM