小编use*_*202的帖子

Pygame MemoryError

我写了一个简单的块收集程序,工作得很好,花花公子,直到我添加声音.然后突然间我得到了一个以前从未见过的MemoryError.

我的代码附加了声音(wav)文件似乎是问题.任何帮助都会很棒,是的,代码和声音都在同一个文件夹中,还有很多其他程序,图片和东西.

import pygame
import random
import pygame.mixer

winsound=pygame.mixer.Sound('winning.wav')
collectsound=pygame.mixer.Sound('blip.wav')
#Define colors

black    = (   0,   0,   0)
white    = ( 255, 255, 255)
red      = ( 255,   0,   0)

#Class represents ball, derives from Sprite class in pygame

class Block(pygame.sprite.Sprite):
    #Constructor. Pass in the color of the block and its x and y pos.
    def __init__(self, color, width, height):
            # Call the parent class (Sprite) constructor
            pygame.sprite.Sprite.__init__(self) 

            # Create an image of the block, and fill it with a …
Run Code Online (Sandbox Code Playgroud)

python memory audio pygame

4
推荐指数
1
解决办法
3320
查看次数

试着看看python中的数字是否为素数

我正在尝试编写一个程序,告诉您数字是否为素数.这里是.正如您在运行该chkPrime函数时所看到的,一切都返回true.我为我的生活无法弄明白.有任何想法吗?

total=0

#Check if number is whole
def chkWhole(x):

    if(x%1 == 0):

        return True

    else:

        return False




#Check to see if the number divides evenly with all primes
def chkModtwo(n):
    a=n%2
    if chkWhole(a)==True:
        return True
    else:
        return False
def chkModthree(n):
    a=n%3
    if chkWhole(a)==True:
        return True
    else:
        return False
def chkModfive(n):
    a=n%5
    if chkWhole(a)==True:
        return True
    else:
        return False
def chkModseven(n):
    a=n%7
    if chkWhole(a)==True:
        return True
    else:
        return False


#Check if the number is a prime using other two …
Run Code Online (Sandbox Code Playgroud)

python primes function

0
推荐指数
1
解决办法
2039
查看次数

在python中坚持项目Euler#3

13195的主要因素是5,7,13和29. 600851475143中最大的素数是多少?

好的,所以我正在研究python中的项目euler问题3.我有点困惑.我不知道我在这个程序中得到的答案是否正确.如果somone可以请告诉我我做错了什么会很棒!

#import pdb

odd_list=[]
prime_list=[2] #Begin with zero so that we can pop later without errors.

#Define a function that finds all the odd numbers in the range of a number
def oddNumbers(x):

    x+=1 #add one to the number because range does not include it
    for i in range(x):
        if i%2!=0: #If it cannot be evenly divided by two it is eliminated
            odd_list.append(i) #Add it too the list

    return odd_list 

def findPrimes(number_to_test, list_of_odd_numbers_in_tested_number): # Pass in the prime …
Run Code Online (Sandbox Code Playgroud)

python math primes

-1
推荐指数
2
解决办法
7895
查看次数

标签 统计

python ×3

primes ×2

audio ×1

function ×1

math ×1

memory ×1

pygame ×1