如何使用来自随机choi的相同输出

2024-04-27 02:26:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用从列表中随机选择的输出,稍后再使用相同的输出。如何让它使用随机输出的相同输出,而不是另一个随机输出?你知道吗

这是我目前的代码:

print("Good you will have to do two things, first answer my question, second 
guess my number")
speed = int(input("What is the top mph you have reached in the last week?"))
time = ('5','10')
print('You have traveled at' ,speed, 'mph for' ,random.choice(time), 
'hours.' )
distance = int(input('How many miles have you traveled?'))
if distance == speed * int(random.choice(time)):
  print('Good job, now simply guess my number.')
else:
  print("Better luck next time, looks like you don't know your velocity equation")

“int”(随机选择(time))“在这里我想使用与上面两行打印中相同的输出。你知道吗

对不起,如果这是一个很容易问的问题,这是我第一次用python编程。你知道吗


Tags: theyounumberinputtimemyhaverandom