shigure_takimi 发表于 2017-12-8 14:40:16

import random
##之前用Pygame写的一个双色球选号程序。

import pygame
from pygame.locals import *

BLACK =
RED =
GREEN =
BLUE =
YELLOW =
WHITE =

WIDTH = 800
HEIGHT = 600


pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Double Color Ball')
font1 = pygame.font.SysFont('Arial', 40)

def printText(text, y, shadow = True):
    if shadow:
      textImg = font1.render(text, True, RED)
      screen.blit(textImg, (WIDTH//2 - textImg.get_width()//2 - 2, y - 2))
    textImg = font1.render(text, True, YELLOW)
    screen.blit(textImg, (WIDTH//2 - textImg.get_width()//2, y))


class Ball(pygame.sprite.Sprite):
    def __init__(self):
      super().__init__()
      self.image = pygame.Surface(((80+20)*6+80, 80))
      self.rect = self.image.get_rect()
      self.rect.center = WIDTH//2, HEIGHT//2
      self.numbers = []
      self.selected = False
    def getNumbers(self):
      if not self.selected:
            allRedBalls = list(range(1, 34))
            redBalls = []
            for i in range(6):
                number = random.choice(allRedBalls)
                allRedBalls.remove(number)
                redBalls.append(number)
            blueBall = random.randint(1, 16)
            self.numbers = sorted(redBalls)
            self.numbers.append(blueBall)
    def update(self):
      self.image.fill(GREEN)
      self.getNumbers()
      for i in range(7):
            if i < 6:
                pygame.draw.circle(self.image, RED, (i*100+40, 40), 40)
            else:
                pygame.draw.circle(self.image, BLUE, (i*100+40, 40), 40)
            numberImg = font1.render(str(self.numbers), True, YELLOW)
            numberImgRect = numberImg.get_rect()
            numberImgRect.center = (i*100+40, 40)
            self.image.blit(numberImg, numberImgRect)
      

allGroup = pygame.sprite.Group()
balls = Ball()
allGroup.add(balls)

done = False
while not done:
    for event in pygame.event.get():
      if event.type == QUIT:
            done = True
      elif event.type == MOUSEBUTTONDOWN and event.button == 1:
            if balls.selected == True:
                balls.selected = False
            else:
                balls.selected = True

    screen.fill(GREEN)
    allGroup.update()
    allGroup.draw(screen)
    printText('DOUBLE COLOR BALL', 100)
    printText('CLICK TO SELECT', 450)
    pygame.display.flip()

pygame.quit()
http://xxx.fishc.com/forum/201705/02/085631uj84jfifiweif4z4.png

kelebuyoatang 发表于 2017-12-8 14:57:06

shigure_takimi 发表于 2017-12-8 14:57:06

import random

def selectBalls():
    count = input('请问选几注?\n')
    if (not count.isdigit()) or (count.isdigit() and str(count) == '0'):
      print('滚犊子!')
    else:            
      result = []
      for i in range(int(count)):
            red = list(range(1,34))
            random.shuffle(red)
            redBalls = sorted(red)
            blueBall = random.randint(1,16)
            result.append((redBalls, blueBall))
      for i,balls in enumerate(result):
            print('\n第{0}注:\n红球:{1}\n蓝球:{2}'.format(i+1, balls, balls))
      print('\n祝您拿大奖!')


selectBalls()

##    >>>
##    请问选几注?
##    5
##
##    第1注:
##    红球:
##    蓝球:10
##
##    第2注:
##    红球:
##    蓝球:10
##
##    第3注:
##    红球:
##    蓝球:10
##
##    第4注:
##    红球:
##    蓝球:4
##
##    第5注:
##    红球:
##    蓝球:5
##
##    祝您拿大奖!


shigure_takimi 发表于 2017-12-8 14:57:51

import random

def selectBalls():
    count = input('请问选几注?\n')
    if (not count.isdigit()) or (count.isdigit() and str(count) == '0'):
      print('滚犊子!')
    else:            
      result = []
      for i in range(int(count)):
            red = list(range(1,34))
            random.shuffle(red)
            redBalls = sorted(red)
            blueBall = random.randint(1,16)
            result.append((redBalls, blueBall))
      for i,balls in enumerate(result):
            print('\n第{0}注:\n红球:{1}\n蓝球:{2}'.format(i+1, balls, balls))
      print('\n祝您拿大奖!')


selectBalls()

##    >>>
##    请问选几注?
##    5
##
##    第1注:
##    红球:
##    蓝球:10
##
##    第2注:
##    红球:
##    蓝球:10
##
##    第3注:
##    红球:
##    蓝球:10
##
##    第4注:
##    红球:
##    蓝球:4
##
##    第5注:
##    红球:
##    蓝球:5
##
##    祝您拿大奖!


huangxr 发表于 2017-12-8 15:22:15

1

beetb 发表于 2017-12-8 16:08:00

厲害的東西

kobe0805 发表于 2017-12-31 19:25:57

呵呵。。。。这个可以有

LBjames 发表于 2018-1-1 22:43:39

666

胃里有只猪 发表于 2018-1-7 22:18:11

123

萝卜丿 发表于 2018-1-12 13:24:49

想看唉

nn_nolan 发表于 2018-1-22 22:34:50

学习下,多谢分享~~~~

塔利班 发表于 2018-1-22 22:41:27

1

塔利班 发表于 2018-1-22 22:43:02

传说中的小角色 发表于 2017-2-25 23:09
你好,我是0基础,装好软件,然后逛帖子,看见这个复制了,代码一直报错,请问下这个怎么解决

你要新建文件,复制进去,CTRL+N

塔利班 发表于 2018-1-22 22:44:35

你们想的都太简单了,不如编个程序,彩票网站获得大数据后,如何让中奖累积金额最小{:10_266:}

笑傲江湖1 发表于 2018-4-5 20:22:31

喜欢哦 手收下了

lvjie 发表于 2018-4-5 22:02:31

指教

LeeA 发表于 2018-4-16 13:04:22

xxuexi le

fisherman007 发表于 2018-4-16 19:08:54

想看看阁下的作品

Y丶Deneral 发表于 2018-4-17 04:15:01

机智

ADYJ 发表于 2018-4-17 18:28:47

{:5_90:}
页: 1 2 [3] 4 5 6 7 8
查看完整版本: 自己动手写了一个双色球机选小程序