Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #this creates a class named Player
  2. class Player(object):
  3. #this creates a function called __init__ and it has the parameters self, player, age, and goals and you set the 1,2,and 3rd parameters to self
  4. def __init__(self, player, age, goals):
  5. self.player = player
  6. self.age = age
  7. self.goals = goals
  8. #the getStats fucntion stores the information of the player like their name, age, and goals
  9. def getStats(self):
  10. summary = "Player: " + self.player + "\n"
  11. summary = summary + "Age: " + self.age + "\n"
  12. summary = summary + "Goals: " + self.goals + "\n"
  13. return summary
  14. print(getStats)
  15. #the getGoals function returns the goals the player has scored
  16. def getGoals(self):
  17. return self.goals
  18. print(getGoals)
  19. #myPlayers is an empty list that the user can add players later on
  20. myPlayers = []
  21. #used to create a while statement later on
  22. sport = "soccer"
  23.  
  24. #the while statement is used so that the user can see the options they can choose
  25. while sport == "soccer":
  26. print("What would you like to do? Enter the number of your choice and press enter.")
  27. print("(1) Add a player")
  28. print("(2) Print all players")
  29. print("(3) Print average number of goals for all payers")
  30.  
  31. #response is equal to raw_input to let the user decide what option they want to choose
  32. response = input()
  33. #if the user chooses 1 it will ask the the player's info
  34. if response == 1:
  35. print("Enter your player's name and press enter")
  36. playerName = input()
  37. print("Enter age of the player")
  38. playerAge = input()
  39. print("How many goals have they scored this season?")
  40. playerGoals = input()
  41. my_Player = Player(playerName, playerAge, playerGoals)
  42. myPlayers.append(my_Player)
  43. print("Player now added to the team!")
  44. #this will run if the user chooses choice 2 and it will display the players by using the getStats method
  45. elif response == 2:
  46. print("Here's a list of the players")
  47. for p in myPlayers:
  48. print(p.getStats())
  49. #this will print if the user chooses choice 3 and it will print the average number of goals each player made
  50. elif response == 3:
  51. count = 1
  52. number = 1
  53. for l in myPlayers:
  54. count = count + int(l.getGoals())
  55. number = number + 1
  56. print(count / number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement