任务是创建一个生成随机整数的程序。以下是程序的行为方式:
Enter the lower bound:10
Enter the upper bound: 23
14
如您所见,程序首先要求用户输入一个整数。然后,一旦用户输入一个数字,程序就会再次要求用户输入另一个数字。
然后,程序返回一个介于两个整数之间的随机数。这是另一个例子:
import random
lower = int(int("Enter the lowerBound: "))
upper = int(int("Enter the upperBound: "))
ans = random.randint(lower, upper)
print(ans)
这是通过使用Python随机库的randint()函数来实现的