Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 Powerball号码生成器:_Python_Python 2.7 - Fatal编程技术网

Python Powerball号码生成器:

Python Powerball号码生成器:,python,python-2.7,Python,Python 2.7,我希望我的输出按递增顺序排列,如: 你的号码:31242647强力球:2 你的号码:1 4 31 34 51力量球:17 你的号码:10124953力量球:35 但我的代码给了我这样的信息: Ofical Powerball数字发生器 有多少组数字?5 你的号码:4129134315力量球:29 你的号码:444184751强力球:15 你的号码:247392847力量球:19 你的号码:3946182319力量球:41 你的号码:49 21 47 37 1力量球:8 import random

我希望我的输出按递增顺序排列,如:

你的号码:31242647强力球:2
你的号码:1 4 31 34 51力量球:17
你的号码:10124953力量球:35

但我的代码给了我这样的信息:

Ofical Powerball数字发生器
有多少组数字?5
你的号码:4129134315力量球:29
你的号码:444184751强力球:15
你的号码:247392847力量球:19
你的号码:3946182319力量球:41
你的号码:49 21 47 37 1力量球:8

import random
print "Ofical Powerball number generator"
x = int(raw_input("How many sets of numbers? "))
z = range(1,42)

for n in range(x):
  z1 = random.choice(z)
  i = random.sample(range(1,53), 5)
  q = i[0]
  w = i[1]
  e = i[2]
  r = i[3]
  t = i[4]
  print "Your numbers: " + str(q), str(w), str(e), str(r), str(t) +  " Powerball: "+ str(z1)

如何让代码中的最后一行按顺序显示数字?

您可以将作业预排序到
I

i = sorted(random.sample(range(1, 53), 5))

您可以将作业预排序到
i

i = sorted(random.sample(range(1, 53), 5))

我为每次抽签都添加了随机种子,这样其他只运行MersenneTwister的人就不太可能得到相同的选择

import random
print "Powerball number generator"
x = int(raw_input("How many sets of numbers? "))

for i in range( x ):
  white = range( 1, 70 )
  n = [None] * 5
  for j in range( len(n) ):
    random.SystemRandom()
    n[j] = random.sample( white, 1 ).pop()
    white.remove( n[j] )

  n.sort()
  random.SystemRandom()
  powerball = random.choice( range( 1, 27 ) )
  print( "Your numbers: " ),
  for j in range( 5 ):
    print( str(n[j]).rjust(2) + " " ),
  print( "\tPowerball: "+ str(powerball) )

我为每次抽签都添加了随机种子,这样其他只运行MersenneTwister的人就不太可能得到相同的选择

import random
print "Powerball number generator"
x = int(raw_input("How many sets of numbers? "))

for i in range( x ):
  white = range( 1, 70 )
  n = [None] * 5
  for j in range( len(n) ):
    random.SystemRandom()
    n[j] = random.sample( white, 1 ).pop()
    white.remove( n[j] )

  n.sort()
  random.SystemRandom()
  powerball = random.choice( range( 1, 27 ) )
  print( "Your numbers: " ),
  for j in range( 5 ):
    print( str(n[j]).rjust(2) + " " ),
  print( "\tPowerball: "+ str(powerball) )

在打印变量之前对其进行排序。就我个人而言,我会使用。在打印变量之前对变量进行排序。就我个人而言,我会使用。