python實現雙色球機選功能

來源:互聯網
上載者:User

python實現雙色球機選功能

import randomblue = [x for x in range (1,17)]red = [y for y in range (1,34)]print "The blue ball is :", random.choice(blue)for n in range(1,7):    print "The %d red ball is :" %n, red.pop(random.randint(0, (len(red)-1)))

>>> ================================ RESTART ================================>>> The blue ball is : 3The 1 red ball is : 17The 2 red ball is : 22The 3 red ball is : 26The 4 red ball is : 30The 5 red ball is : 27The 6 red ball is : 25>>> ================================ RESTART ================================>>> The blue ball is : 9The 1 red ball is : 32The 2 red ball is : 23The 3 red ball is : 15The 4 red ball is : 8The 5 red ball is : 17The 6 red ball is : 9>>> ================================ RESTART ================================>>> The blue ball is : 6The 1 red ball is : 15The 2 red ball is : 16The 3 red ball is : 11The 4 red ball is : 23The 5 red ball is : 10The 6 red ball is : 27>>> 

產生過程:red list 依次減少已經取到的紅球號數,避免重複抽取到同一個號碼;

import randomblue = [x for x in range (1,17)]red = [y for y in range (1,34)]print "The blue ball is :", random.choice(blue),'\n'for n in range(1,7):    print "The %d red ball are :" %n,red.pop(random.randint(0, (len(red)-1))), '\n'    print "Now the red ball be left are:",red, '\n'

>>> The blue ball is : 2 The 1 red ball is : 26 Now the red ball be left are: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33] The 2 red ball is : 25 Now the red ball be left are: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 28, 29, 30, 31, 32, 33] The 3 red ball is : 14 Now the red ball be left are: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 28, 29, 30, 31, 32, 33] The 4 red ball is : 29 Now the red ball be left are: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 28, 30, 31, 32, 33] The 5 red ball is : 8 Now the red ball be left are: [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 28, 30, 31, 32, 33] The 6 red ball is : 31 Now the red ball be left are: [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 28, 30, 32, 33] >>> 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.