Advertisement
furas

Poprawki i sugestie

Jun 1st, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. # oryginalne
  2.  
  3. def generate(self):
  4.         if config.allow_bonuses==True:
  5.             return "Bonus: OFF"
  6.             config.allow_bonuses == False
  7.         elif config.allow_bonuses==False:
  8.             return "Bonus: ON"
  9.             config.allow_bonuses==True
  10.  
  11. # poprawione
  12.  
  13. def generate(self):
  14.     if config.allow_bonuses:  # rownowazne z uzyciem  == True
  15.         config.allow_bonuses = False  # pojedynczy znak równości
  16.         return "Bonus: OFF"           # `return` jako ostatnia linia
  17.     else:  # nie trzeba sprawdzać już czy jest False
  18.         config.allow_bonuses = True
  19.         return "Bonus: ON"
  20.  
  21. # inaczej zrobione
  22.  
  23. def generate(self):
  24.     # przelaczenie stanu na przeciwny
  25.     config.allow_bonuses = not config.allow_bonuses
  26.  
  27.     # zwrocenie odpowiedniej wartosci
  28.     # korzystajac ze specjalnej postaci `if/else`
  29.     return "Bonus: ON" if config.allow_bonuses else "Bonus: OFF"
  30.  
  31. //////////////////////////////////////////////////
  32.  
  33. # oryginal
  34.  
  35. def generate(self):
  36.         for event in pygame.event.get():
  37.             if config.allow_bonuses == True and event.type == pygame.K_RETURN:
  38.                return "Bonus: OFF"
  39.                config.allow_bonuses == False
  40.             elif not config.allow_bonuses == False and event.type == pygame.K_RETURN:
  41.                return "Bonus: ON"
  42.                config.allow_bonuses == True
  43.  
  44. # poprawione
  45.  
  46. def generate(self):
  47.     for event in pygame.event.get():
  48.         if event.type == pygame.K_RETURN: # wyciagniecie wspólnego elementu
  49.             if config.allow_bonuses:
  50.                config.allow_bonuses = False
  51.                return "Bonus: OFF"
  52.             else :
  53.                config.allow_bonuses = True
  54.                return "Bonus: ON"
  55.  
  56. # inaczej zrobione
  57.  
  58. def generate(self):
  59.     for event in pygame.event.get():
  60.         if event.type == pygame.K_RETURN:
  61.           # przelaczenie stanu na przeciwny
  62.           config.allow_bonuses = not config.allow_bonuses
  63.  
  64.           # zwrocenie odpowiedniej wartosci
  65.           # korzystajac ze specjalnej postaci `if/else`
  66.           return "Bonus: ON" if config.allow_bonuses else "Bonus: OFF"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement