Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  • according to PEP8 commenting guidelines, there has to be two spaces before the # and once space after
  • there is no need for spaces around the = for keyword function or method arguments (PEP8 reference)
  • put the main execution code to under if __name__ == '__main__': if __name__ == '__main__': to avoid it being executed on import
  • let's define 10 as a constant to avoid hardcoding things
  • I'd also use something like a total_points variable name instead of a more questionable overall
  • according to PEP8 commenting guidelines, there has to be two spaces before the # and once space after
  • there is no need for spaces around the = for keyword function or method arguments (PEP8 reference)
  • put the main execution code to under if __name__ == '__main__': to avoid it being executed on import
  • let's define 10 as a constant to avoid hardcoding things
  • I'd also use something like a total_points variable name instead of a more questionable overall
  • according to PEP8 commenting guidelines, there has to be two spaces before the # and once space after
  • there is no need for spaces around the = for keyword function or method arguments (PEP8 reference)
  • put the main execution code to under if __name__ == '__main__': to avoid it being executed on import
  • let's define 10 as a constant to avoid hardcoding things
  • I'd also use something like a total_points variable name instead of a more questionable overall
added 197 characters in body
Source Link
alecxe
  • 17.5k
  • 8
  • 52
  • 93
  • according to PEP8 commenting guidelines, there has to be two spaces before the # and once space after
  • there is no need for spaces around the = for keyword function or method arguments (PEP8 reference)
  • put the main execution code to under if __name__ == '__main__': to avoid it being executed on import
  • let's define 10 as a constant to avoid hardcoding things
  • I'd also use something like a total_points variable name instead of a more questionable overall
POINTS_FOR_STRIKE = 10
class BowlingPlayer(object):
 def __init__(self, name, overall=0):
 self.name = name
 self.overalltotal_points = overall
 def frames(self):
 shot_one = int(input('how many pins on first shot:'))
 if shot_one == 10POINTS_FOR_STRIKE: # this is a strike
 shot_two_after_strike = int(input('how many pins on shot after strike:'))
 self.overalltotal_points += shot_two_after_strike + shot_one
 if shot_two_after_strike == 10POINTS_FOR_STRIKE: # you got another strike. continue the frame!
 shot_three_after_strike = int(input('how many pins on shot after two strikes:'))
 self.overalltotal_points += shot_three_after_strike
 elif shot_one < 10POINTS_FOR_STRIKE:
 shot_two = int(input('how many pins on second shot:'))
 shots = shot_one + shot_two
 self.overalltotal_points += shots
 if shots == 10POINTS_FOR_STRIKE: # this is a spare
 shot_three_after_spare = int(input('how many pins on shot after spare')) 
 self.overalltotal_points += shot_three_after_spare
 return self.overalltotal_points
if __name__ == '__main__':
 craig = BowlingPlayer('craig')
 print(craig.frames())

I'd also use something like a total_points variable name instead of a more questionable overall.

class BowlingPlayer(object):
 def __init__(self, name, overall=0):
 self.name = name
 self.overall = overall
 def frames(self):
 shot_one = int(input('how many pins on first shot:'))
 if shot_one == 10: # this is a strike
 shot_two_after_strike = int(input('how many pins on shot after strike:'))
 self.overall += shot_two_after_strike + shot_one
 if shot_two_after_strike == 10: # you got another strike. continue the frame!
 shot_three_after_strike = int(input('how many pins on shot after two strikes:'))
 self.overall += shot_three_after_strike
 elif shot_one < 10:
 shot_two = int(input('how many pins on second shot:'))
 shots = shot_one + shot_two
 self.overall += shots
 if shots == 10: # this is a spare
 shot_three_after_spare = int(input('how many pins on shot after spare')) 
 self.overall += shot_three_after_spare
 return self.overall
if __name__ == '__main__':
 craig = BowlingPlayer('craig')
 print(craig.frames())

I'd also use something like a total_points variable name instead of a more questionable overall.

  • according to PEP8 commenting guidelines, there has to be two spaces before the # and once space after
  • there is no need for spaces around the = for keyword function or method arguments (PEP8 reference)
  • put the main execution code to under if __name__ == '__main__': to avoid it being executed on import
  • let's define 10 as a constant to avoid hardcoding things
  • I'd also use something like a total_points variable name instead of a more questionable overall
POINTS_FOR_STRIKE = 10
class BowlingPlayer(object):
 def __init__(self, name, overall=0):
 self.name = name
 self.total_points = overall
 def frames(self):
 shot_one = int(input('how many pins on first shot:'))
 if shot_one == POINTS_FOR_STRIKE: # this is a strike
 shot_two_after_strike = int(input('how many pins on shot after strike:'))
 self.total_points += shot_two_after_strike + shot_one
 if shot_two_after_strike == POINTS_FOR_STRIKE: # you got another strike. continue the frame!
 shot_three_after_strike = int(input('how many pins on shot after two strikes:'))
 self.total_points += shot_three_after_strike
 elif shot_one < POINTS_FOR_STRIKE:
 shot_two = int(input('how many pins on second shot:'))
 shots = shot_one + shot_two
 self.total_points += shots
 if shots == POINTS_FOR_STRIKE: # this is a spare
 shot_three_after_spare = int(input('how many pins on shot after spare')) 
 self.total_points += shot_three_after_spare
 return self.total_points
if __name__ == '__main__':
 craig = BowlingPlayer('craig')
 print(craig.frames())
added 102 characters in body
Source Link
alecxe
  • 17.5k
  • 8
  • 52
  • 93

I'd also use something like a total_points variable name instead of a more questionable overall.

I'd also use something like a total_points variable name instead of a more questionable overall.

Source Link
alecxe
  • 17.5k
  • 8
  • 52
  • 93
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /