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
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
##
## 祝您拿大奖!
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
##
## 祝您拿大奖!
1
厲害的東西
呵呵。。。。这个可以有
666
123
想看唉
学习下,多谢分享~~~~
1
传说中的小角色 发表于 2017-2-25 23:09
你好,我是0基础,装好软件,然后逛帖子,看见这个复制了,代码一直报错,请问下这个怎么解决
你要新建文件,复制进去,CTRL+N
你们想的都太简单了,不如编个程序,彩票网站获得大数据后,如何让中奖累积金额最小{:10_266:}
喜欢哦 手收下了
指教
xxuexi le
想看看阁下的作品
机智
{:5_90:}