Advertisement
dmesticg

Untitled

Jun 29th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. def readfiletolist(filename):
  2. data = []
  3. with open(filename, "r") as a:
  4. data = a.read()
  5. data = data.replace("\n","")
  6. data = data.split("-")
  7. del data[-1]
  8. return(data)
  9.  
  10. data = readfiletolist("stats.txt")
  11. stat_types = []
  12. stat_worths = []
  13. for i in range(len(data)):
  14. if (i % 2 ) == 0:
  15. stat_types.append(data[i])
  16. else:
  17. stat_worths.append(float(data[i]))
  18.  
  19. def calculateWinLoss(team,list_position): ##list_position is the position of the stat "lineup's number of maps played"
  20. winloss = team[list_position+1] / team[list_position] ##make sure "lineup's number of wins" comes right after
  21. del team[list_position+1]
  22. team.append(winloss)
  23. return(team)
  24.  
  25. def teamRankingFix(t1,t2,list_position): ##list_position is the position of the stat "current ranking"
  26. t1[list_position], t2[list_position] = t2[list_position],t2[list_position]
  27. t1[list_position+1], t2[list_position+1] = t2[list_position+1],t2[list_position+1] ##make sure peak ranking" comes right after
  28. return(t1,t2)
  29.  
  30. def askTeamInfo(team,stat_types):
  31. for i in range(len(stat_types)):
  32. team.append(int(input("{}'s {}".format(team[0],stat_types[i]))))
  33. return(team)
  34.  
  35. def comparison(team1,team2,worths):
  36. t1score = 0
  37. t2score = 0
  38. t1 = team1[:]
  39. t2 = team2[:]
  40. del t1[0]
  41. del t2[0]
  42. for i in range(len(t1)):
  43. if t1[i] != t2[i]:
  44. big = max(t1[i],t2[i])
  45. small = min(t1[i],t2[i])
  46. abs_dif = abs(big-small) ##absolute difference between the 2 values
  47. average = (big + small) / 2 ##average of the 2 values
  48. percent_dif = abs_dif / average ##divide the difference by the average to get percent difference
  49. big_score = percent_dif * worths[i]
  50. print("{} {}".format(big,big_score))
  51. print("{} {}".format(small,worths[i]-big_score))
  52. if t1[i] == big:
  53. t1score += big_score
  54. t2score += worths[i] - big_score
  55. else:
  56. t2score += big_score
  57. t1score += worths[i] - big_score
  58. else:
  59. t1score += worths[i] / 2
  60. t2score += worths[i] / 2
  61. return(t1score,t2score)
  62.  
  63.  
  64. team1 = []
  65. team2 = []
  66. team1.append(input("What is Team1's Name?"))
  67. team1 = askTeamInfo(team1,stat_types)
  68. team2.append(input("What is Team2's Name?"))
  69. team2 = askTeamInfo(team2,stat_types)
  70. ##team1,team2 = teamRankingFix(team1,team2,5)
  71. team1 = calculateWinLoss(team1,7)
  72. team2 = calculateWinLoss(team2,7)
  73. team1score,team2score = comparison(team1,team2,stat_worths)
  74. print("{}'s chance to win is {:.2f}%".format(team2[0],team1score))
  75. print("{}'s chance to win is {:.2f}%".format(team1[0],team2score))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement