Python 3.7.1 Pygame 1.9.4错误:TypeError:预期为整数参数,浮点数

时间:2018-12-16 13:46:40

标签: python pygame

因此,我正在构建一个非常简单的游戏。我打算跳个圈。直到那一切都很好。但是,当我尝试将跳跃添加到游戏中时,出现了一个错误消息,告诉我“ TypeError:预期为整数参数,出现了浮点数”,我多次检查了代码。我似乎找不到错误。因此,我正在寻求帮助。这是我的代码:

import pygame
pygame.init()

win = pygame.display.set_mode((500, 500))

pygame.display.set_caption("A GAME")

screenWidth = 500

x = 100
y = 400
width = 50
height = 50
vel = 10
r = 15

isJump = False

jumpCount = 10

run = True

clock = pygame.time.Clock()

while run:
    pygame.time.delay(100)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    clock.tick(60)

    keys = pygame.key.get_pressed()

    if keys [pygame.K_a] and x > r:
        x -= vel
    if keys [pygame.K_d] and x < screenWidth - r:
        x += vel
    if not (isJump):
        if keys [pygame.K_SPACE]:
            isJump = True
    else:
        if jumpCount >= -10:
            neg = 1
            if jumpCount < 0:
                neg = -1
            y -= (jumpCount ** 2) * 0.5 * neg
            jumpCount -= 1
        else:
            isJump = False
            jumpCount = 10
    if keys [pygame.K_ESCAPE]:
        run = False

    win.fill((0, 0, 0))


    pygame.draw.circle(win, (255, 0, 0), (x, y), r, 0)
    pygame.display.update()

pygame.quit()

plz帮助

3 个答案:

答案 0 :(得分:1)

此行:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-9-bda887b4022f> in <module>
     27 # create the ensemble model
     28 ensemble = VotingClassifier(estimators)
---> 29 results = model_selection.cross_val_score(ensemble, X, Y, cv=kfold)
     30 print(results.mean())

/usr/local/lib/python3.5/dist-packages/sklearn/model_selection/_validation.py in cross_val_score(estimator, X, y, groups, scoring, cv, n_jobs, verbose, fit_params, pre_dispatch, error_score)
    400                                 fit_params=fit_params,
    401                                 pre_dispatch=pre_dispatch,
--> 402                                 error_score=error_score)
    403     return cv_results['test_score']
    404 
...
...
NotImplementedError: Multilabel and multi-output classification is not supported.

应更改为:

pygame.draw.circle(win, (255, 0, 0), (x, y), r, 0)

因为y是此行之后的浮点数:

pygame.draw.circle(win, (255, 0, 0), (x, int(y)), r, 0)

或者您可以这样解决它:

y -= (jumpCount ** 2) * 0.5 * neg

Rudy的答案将起作用,并且Floor Division(//)的输出是一个int:

y -= int((jumpCount ** 2) * 0.5 * neg)

答案 1 :(得分:0)

您的代码中唯一的function armNum(){ var num = prompt("Enter a number between 0 and 999!: "); var firstNum; var secondNum; var thirdNum; if(num < 100 && num > 0) { firstNum = num/10; secondNum = num%10; var StrongNum = (firstNum**3) + (secondNum**3); if( num == StrongNum) { document.getElementById("ispis").innerHTML = "nummber " + num + " is an armstrong number!" } else { document.getElementById("ispis").innerHTML = "number" + num + "is not an armstrong number!" } } if(num > 99 && num < 1000) { firstNum = num/100; secondNum = (num/10)%10; thirdNum = num % 10; var StrongNum = (firstNum**3) + (secondNum**3) = (thirdNum**3); if( num == StrongNum) { document.getElementById("ispis").innerHTML = "nummber " + num + " is an armstrong number!" } else { document.getElementById("ispis").innerHTML = "number" + num + "is not an armstrong number!" } } } float;您可能会想要

y

代替

答案 2 :(得分:0)

使用0.5会将y转换为浮点数。我想那不是你想要的。所以把它变成:

y -= (jumpCount * jumpCount) // 2 * neg