乐透程序随机编号生成器

发布于 2025-02-11 08:09:41 字数 154 浏览 1 评论 0原文

我想创建一个程序,其中将选择一组指定号码的组中有4个,并且还将选择另一个指定号码中的2个。例如:(55、50,45、30、3、12、36、9,8,13)中,将有4个数字随机选择。然后另一组(例如(54、43、21、39、46,20,1,5,11)将有另外2个数字随机选择是唯一的。我该如何编码?

I would like to create a program where 4 out of a group of a specified number will be chosen and another 2 out of another specified number will be chosen as well. For example: ( 55, 50,45, 30, 3, 12, 36, 9,8,13) out of this set, there will be 4 numbers that will be randomly chosen. and then another set for example (54, 43, 21, 39, 46,20,1,5,11) there will be another 2 numbers that will be randomly chosen that are unique. How can I code that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耳根太软 2025-02-18 08:09:41

我决定在Python撰写我的实施。这将从第一个列表中输出4个唯一值,第二个列表中的两个唯一值。我认为这就是您的代码外观:

import random

list1 = [55, 50,45, 30, 3, 12, 36, 9,8,13]
list2 = [54, 43, 21, 39, 46,20,1,5,11]

picked1 = random.sample(list1, 4)
picked2 = random.sample(list2, 2)

print("First Pick:")

for i in picked1:
  print(i)

print("Second Pick:")

for j in picked2:
  print(j)

希望这会有所帮助!

I decided to write my implementation in Python. This will output 4 unique values from the first list and two unique values from the second list. I think this is what your code should look like:

import random

list1 = [55, 50,45, 30, 3, 12, 36, 9,8,13]
list2 = [54, 43, 21, 39, 46,20,1,5,11]

picked1 = random.sample(list1, 4)
picked2 = random.sample(list2, 2)

print("First Pick:")

for i in picked1:
  print(i)

print("Second Pick:")

for j in picked2:
  print(j)

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文