Answers for "Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through __init__."

0

Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through __init__.

import re

string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''

players = re.search(r'''
    ^(?P<last_name>[-\w\s?]*),\s   # Last Names
    (?P<first_name>[-\w\s?]+):\s   # First Names
    (?P<score>[\d]+)   # Score
$''', string, re.X|re.M)   # VERBOSE and MULTILINE

class Player:
  last_name = str()
  first_name = str()
  score = str()

  def __init__(self, **players.groupdict()):
    self.last_name = input('last name: ')
    self.first_name = input('first_name: ')
    self.score = input('score: ')
Posted by: Guest on September-24-2021
0

Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through __init__.

import re

string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''

players = re.search(r'''
    (?P<last_name>[-\w\s?]*),\s   # Last Names
    (?P<first_name>[-\w\s?]+):\s   # First Names
    (?P<score>[\d]+)   # Score
''', string, re.X|re.M)   # VERBOSE and MULTILINE

class Player:
  last_name = str()
  first_name = str()
  score = str()

  def __init__(self, **players.groupdict()):
    self.last_name = input('last name: ')
    self.first_name = input('first_name: ')
    self.score = input('score: ')
Posted by: Guest on September-24-2021
0

Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through __init__.

class Player:
  last_name = ""
  first_name = ""
  score = ""

  def __init__(self, last_name=last_name, first_name=first_name, score=score):
    self.last_name = last_name
    self.first_name = first_name
    self.score = score

# Here is a simplified version that does not set class attributes nor use the class attributes as
# '__init__' defaults. This also passes the challenge:

class Player:
  def __init__(self, last_name, first_name, score):
    self.last_name = last_name
    self.first_name = first_name
    self.score = score
Posted by: Guest on September-24-2021

Code answers related to "Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through __init__."

Browse Popular Code Answers by Language