pygame代码中的缩进错误

时间:2015-05-12 16:57:28

标签: python while-loop pygame indentation

以下是代码:

#Imports
import pygame,sys,time,random,cx_Freeze
pygame.init()
pygame.font.init()

#Variables
sizex = 1000
sizey = 700
gametitle = "Calorie Calculator v2"

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

banana = True
sportscar = False

bg = pygame.image.load("bg.png")
icon = pygame.image.load("icon.png")

#Functions

def messagetoscreen (msg, color, size, x, y) :
    font = pygame.font.SysFont(None, size)
    text = font.render(msg, True, color)
    gamedisplay.blit(text, (x, y))

#Initialization

gamedisplay = pygame.display.set_mode((sizex, sizey))
pygame.display.set_caption(gametitle)
pygame.display.set_icon(icon)

#Game Loop

while banana:
    gamedisplay.fill(white)
    messagetoscreen("Calorie Calculator", black, 75, sizex / 2 - 150, 100)
    messagetoscreen("by Brady, Ryan, Nathan, and Charles", black, 35, sizex / 2 - 150, 200)
    messagetoscreen("Pess P To Start", green, 45, sizex / 2 - 150, 300)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            quit()
        if event.type == KEYDOWN:
            if event.key == K_p:
                banana = False
                sportscar = True

    pygame.display.update()

while sportscar:
        gamedisplay.fill(white)
    gamedisplay.blit(bg, (0, 0))
    messagetoscreen("Enter your food on the command line: ", black, 75, sizex / 2 - 150, 200)
    calories = input("What is your food ? : ")
    messagetoscreen("Enter your weight on the command line: ", black, 75, sizex / 2 - 150, 300)
    weight = input("What is your weight ? : ")
    messagetoscreen("Enter your exercise on the command line: ", black, 75, sizex / 2 - 150, 400)
    exercise = input("What is your exercise ? : ")

    for event in pygame.event.get:
            if event.type == QUIT:
                    pygame.quit()
                    quit()  
pygame.display.update()

if exercise == "sitting" :
    exercise = 0.009
elif exercise == "basketball" :
    exercise = 0.063
elif exercise == "walking" :
    exercise = 0.019
elif exercise == "softball" :
    exercise = 0.0038
elif exercise == "weight training" :
    exercise = 0.039
elif exercise == "jogging" :
    exercise = 0.063
elif exercise == "bowling" :
    exercise = 0.023
elif exercise == "fast biking" :
    exercise = 0.045
elif exercise == "swimming" :
    exercise = 0.064
elif exercise == "slow biking" :
    exercise = 0.029
elif exercise == "ice skating" :
    exercise = 0.53
elif exercise == "soccer" :
    exercise = 0.076
elif exercise == "golf" :
    exercise = 0.033
elif exercise == "sitting" :
    exercise = 0.009
elif exercise == "tennis" :
    exercise = 0.061
elif exercise == "jump rope" :
    exercise = 0.083
else :
        print("That exercise is invalid!")
        input()
        quit()

if calories == "big mac" :
    calories = 560.0
elif calories == "large fries" :
    calories = 400.0
elif calories == "large coca-cola" :
    calories = 310.0
elif calories == "salad no dressing" :
    calories = 20.0
elif calories == "butter" :
    calories = 813.0
elif calories == "american cheese" :
    calories = 100.0
elif calories == "yogurt" :
    calories = 150.0
elif calories == "goldfish" :
    calories = 140.0
elif calories == "apricot" :
    calories = 20.0
elif calories == "avacado" :
    calories = 380.0
elif calories == "banana" :
    calories = 101.0
elif calories == "cantaloupe" :
    calories = 160.0
elif calories == "grape" :
    calories = 2.0
elif calories == "plum" :
    calories = 35.0
elif calories == "apple juice" :
    calories = 117.0
elif calories == "grapefruit juice" :
    calories = 96.0
elif calories == "kfc biscut" :
    calories = 235.0
elif calories == "orange juice" :
    calories = 112.0
elif calories == "mcd apple pie" :
    calories = 260.0
elif calories == "mcd cheeseburger" :
    calories = 310.0
elif calories == "chicken mcnugget" :
    calories = 48.0
elif calories == "mcd chicken salad" :
    calories = 140.0
elif calories == "mcd chocolate chip cookies" :
    calories = 330.0
elif calories == "egg mcmuffin" :
    calories = 330.0
elif calories == "small french fries" :
    calories = 220.0
elif calories == "medium french fries" :
    calories = 320.0
elif calories == "mcd hamburger" :
    calories = 260.0
elif calories == "mcd hash browns" :
    calories = 130.0
elif calories == "mcd ice cream" :
    calories = 140.0
elif calories == "mcd side salad" :
    calories = 60.0
elif calories == "mcd vanilla milkshake" :
    calories = 350.0
elif calories == "ranch dressing" :
    calories = 330.0
elif calories == "bacon" :
    calories = 36.0
elif calories == "spam" :
    calories = 170.0
elif calories == "potato chips" :
    calories = 150.0
elif calories == "pretzel sticks" :
    calories = 111.0
elif calories == "cheetos" :
    calories = 150.0
elif calories == "doritos" :
    calories = 140.0
elif calories == "fritos" :
    calories = 150.0
elif calories == "popcorn" :
    calories = 370.0
elif calories == "pretzels" :
    calories = 117.0
elif calories == "vinegar" :
    calories = 4.0
elif calories == "sugar" :
    calories = 770.0
elif calories == "tb soft taco" :
    calories = 228.0
elif calories == "wendys big classic" :
    calories = 470.0
elif calories == "wendys chicken filet" :
    calories = 200.0
elif calories == "wendys french fries" :
    calories = 300.0
elif calories == "wendys frosty" :
    calories = 400.0
elif calories == "tofu" :
    calories = 81.0
elif calories == "arbys beef and cheddar" :
    calories = 455.0
elif calories == "arbys chicken breast" :
    calories = 493.0
elif calories == "arbys chicken club" :
    calories = 493.0
elif calories == "arbys french fries" :
    calories = 246.0
elif calories == "arbys ham and cheese" :
    calories = 292.0
elif calories == "arbys potato cake" :
    calories = 204.0
elif calories == "arbys roast beef" :
    calories = 353.0
elif calories == "arbys super roast beef" :
    calories = 501.0
elif calories == "arbys turkey deluxe" :
    calories = 375.0
elif calories == "coca-cola classic" :
    calories = 144.0
elif calories == "coca-cola new" :
    calories = 154.0
elif calories == "coffee" :
    calories = 2.0
elif calories == "diet coca-cola" :
    calories = 1.0
elif calories == "diet pepsi" :
    calories = 1.0
elif calories == "sprite" :
    calories = 142.0
elif calories == "croissant" :
    calories = 200.0
elif calories == "bagel" :
    calories = 289.0
elif calories == "blueberry muffin" :
    calories = 112.0
elif calories == "bread cubes" :
    calories = 111.0
elif calories == "rye bread" :
    calories = 61.0
elif calories == "bread" :
    calories = 68.0
elif calories == "whole wheat bread" :
    calories = 67.0
elif calories == "hamburger bun" :
    calories = 119.0
elif calories == "cornbread" :
    calories = 126.0
elif calories == "hot dog bun" :
    calories = 119.0
elif calories == "crescent roll" :
    calories = 100.0
elif calories == "croutons" :
    calories = 200.0
elif calories == "eggo blueberry waffles" :
    calories = 130.0
elif calories == "eggo buttermilk waffles" :
    calories = 120.0
elif calories == "eggo oat bran waffles" :
    calories = 110.0
elif calories == "english muffin" :
    calories = 130.0
elif calories == "french bread" :
    calories = 72.0
elif calories == "hoagie roll" :
    calories = 392.0
elif calories == "oat bran muffin" :
    calories = 110.0
elif calories == "carrots" :
    calories = 102.0
elif calories == "cheddar cheese" :
    calories = 113.0
elif calories == "chicken breast" :
    calories = 142.0
elif calories == "chili with beans" :
    calories = 287.0
elif calories == "chocolate chip cookie" :
    calories = 59.0
elif calories == "wedding cake" :
    calories = 220.0
elif calories == "almond joy" :
    calories = 234.0
elif calories == "butterfinger bar" :
    calories = 275.0
elif calories == "takis" :
    calories = 135.0
elif calories == "RYANISAWESOME" :
    calories = 100000000.0

else :
        print("That food is invalid!")
        input()
        quit()

answer = calories / (float(weight) * float(exercise))
minuteanswer = answer

print("It will take you " ,minuteanswer ," minutes to burn off those calories with your chosen execise.")

print("TA-DA!!!!!!")
input()

这是错误:

(在gamedisplay.blit(bg,(0,0))) 在缩进中的制表符和空格中使用不一致

如果我对这些行进行注释,则下一行具有相同的错误。 我想知道如何修复此错误以及可能发生的任何其他错误。

1 个答案:

答案 0 :(得分:0)

while sportscar:
    gamedisplay.fill(white)
    gamedisplay.blit(bg, (0, 0))