Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何打印Random.Randint()函数的相同返回值_Python - Fatal编程技术网

Python 如何打印Random.Randint()函数的相同返回值

Python 如何打印Random.Randint()函数的相同返回值,python,Python,我想得到一些帮助,以找出一种打印出由Random.randint()函数生成的相同数字的方法。我首先将值赋给一个变量,如下所示: randomPersuade = random.randint(200,5000) 问题是,现在我必须在两个不同的print语句中打印两次从这个函数返回的相同值 userDecide2=input("Since you decided to keep the box, I will offer you" ,randomPersuade, "for the box.\

我想得到一些帮助,以找出一种打印出由Random.randint()函数生成的相同数字的方法。我首先将值赋给一个变量,如下所示:

randomPersuade = random.randint(200,5000)
问题是,现在我必须在两个不同的print语句中打印两次从这个函数返回的相同值

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")


我如何调整它,我打印出相同的值两次,然后我必须生成其他几组随机整数,并做同样的事情,我必须创建另一个随机数(2,3,4,5等)?函数不会为第二个print语句生成新值吗?我会自己测试这个,但我必须先完成其余的代码,然后才能这样做,这需要一段时间。任何能给予的帮助都将不胜感激,谢谢

因为您已经为变量
randomConverse=random.randint(2005000)
分配了一个值,除非您再次执行
randomConverse=random.randint(2005000)
,否则其值不会更改


在此之前,变量的值保持不变,并且您可以多次使用它而不更改其值

,因为您已经为变量
randomConverse=random.randint(2005000)
分配了一个值,除非您再次
randomConverse=random.randint(2005000)
,否则它的值不会更改


在此之前,变量的值保持不变,您可以多次使用它而不改变其值

只有在您调用随机函数时才会调用它。打印变量不会调用随机函数。要使您的
打印
语句正常工作,请将
,randomConverse,
替换为
+str(randomPersudae)+
@JohnAnderson Noted,谢谢!)@JohnAnderson
print()
接受多个参数,并将它们全部打印出来,因此您不需要将它们串联起来。@Lofi您试过代码吗?它应该两次打印相同的数字。@Barmar我刚刚打印了,它又一次打印了相同的值,这是成功的!事实证明,我只需要使用Anderson的建议来运行我的代码,谢谢:)随机函数只有在您调用它时才被调用。打印变量不会调用随机函数。要使您的
打印
语句正常工作,请将
,randomConverse,
替换为
+str(randomPersudae)+
@JohnAnderson Noted,谢谢!)@JohnAnderson
print()
接受多个参数,并将它们全部打印出来,因此您不需要将它们串联起来。@Lofi您试过代码吗?它应该两次打印相同的数字。@Barmar我刚刚打印了,它又一次打印了相同的值,这是成功的!事实证明,我不得不使用安德森的建议来运行代码,谢谢:)
print("You decided to collect the cash amount of", randomPersuade, "Enjoy!")