Https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-dictionaries/projects/scrabble


#1

https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-dictionaries/projects/scrabble

15.letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
letters_to_points={letters:points for letters, points in zip(letters,points)}
letters_to_points[" "]=0
print(letters_to_points)
def score_word(word):
  point_total=0
  for i in word:
    point_total+=letters_to_points.get(i,0)
  return point_total
brownie_points=score_word("BROWNIE")
print(brownie_points)
player_to_words={"player1":["BLUE", "TENNIS", "EXIT"], "wordNerd":["EARTH", "EYES", "MACHINE"], "Lexi Con":["ERASER", "BELLY", "HUSKY"], "Prof Reader":["ZAP", "COMA", "PERIOD"]}
player_to_points={}
for player, words in player_to_words.items():
  player_points=0
  for word in words:
    player_points+=score_word(word)
  player_to_points[player]=player_points
print(player_to_points)

Help me with practice: how I can define: play_word(), update_point_totals()
If you want extended practice, try to implement some of these ideas with the Python you’ve learned:

** play_word() — a function that would take in a player and a word, and add that word to the list of words they’ve played**
** update_point_totals() — turn your nested loops into a function that you can call any time a word is played**
** make your letter_to_points dictionary able to handle lowercase inputs as well**


#2

What have you done so far in attempt to write these functions? We can help you, but we are not going to write these functions for you


#3
leetter=[]
points=[]
letter_to_points={letters:points for letters, points in zip(letters,points)}
letter_to_points[" "]=0
print(letter_to_points)
def score_word(word):
  word=word.upper()
  point_total=0
  for i in word:
    point_total+=letter_to_points.get(i,0)
  return point_total
brownie_points=score_word("brownie")
print(brownie_points)
player_to_words={"player1":["BLUE", "TENNIS", "EXIT"], "wordNerd":["EARTH", "EYES", "MACHINE"], "Lexi Con":["ERASER", "BELLY", "HUSKY"], "Prof Reader":["ZAP", "COMA", "PERIOD"]}
player_to_points={}
for player, words in player_to_words.items():
  player_points=0
  for word in words:
    player_points+=score_word(word)
  player_to_points[player]=player_points
print(player_to_points)
list_of_words_they_played=[]
def play_word(player,word): #so here i try define  function that would take in a player and a word, and add 
  list_of_words_they_played.append(word) #that word to the list of words they’ve played
def update_point_totals(word): # function that you can call any time a word is played
  for i in list_of_words_they_played:
    if word==i:
      print("The word "+word+" already played.")
    else:
      print("The word "+word+" is new in game")
play_word("player","brownie")
update_point_totals("browne")

#4

please post your code with format:

How do I format code in my posts?

so the indent of your code will show


#5

https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/lessons/data-types/exercises/review

class Student:
  def __init__(self, name, year):
    self.name = name
    self.year = year
    self.grades=[]
  def add_grade(self, grade):
    if type(grade) == Grade:
      self.grades.append(grade)
      print(self.grades)
  def __repr__(self):
    return self.name
  def get_average(self, score):
    sum_score = 0
    for i in self.grades:
      average+=i    #_you can't use operator += for class Grade_
      return "Student's average score"+ average/len(self.grades)
    
      
class Grade:
  minimum_passing = 65
  def __init__(self, score):
    self.score=score
  def is_passing(self):
    if self.score>=self.minimum_passing:
      return "Your score is {}, so it is enough for passing".format(self.score)
    else:
      return "Your score is {} < 65, so it is not enough for passing".format(self.score)
  def __repr__(self):
    return str(self.score)
roger =  Student("Roger van der Weyden", 10)
sandro = Student("Sandro Botticelli", 12)
pieter = Student("Pieter Bruegel the Elder", 8)
pieter_grade=Grade(100)
pieter.add_grade(pieter_grade)
sandro.add_grade(Grade(90))
roger.add_grade(Grade(80))
print(pieter_grade)
  • Write a Student method get_average() that returns the student’s average score.
    How I can make it? because when I try call print(self.grades) I see 3 lists, so how I can use it for finding average score

#6

Create a new Grade with a score of 100 and add it to pieter 's .grades attribute using .add_grade()

you didn’t give it a 100 score


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.