Thursday, June 28, 2012
Archery Score
[Original]
from random import randint
def getScore():
rdmScore = []
for a in range(10):
rdmScore.append(randint(100,300))
return rdmScore
rdmScore = getScore()
def lowestScore():
lowest = min(rdmScore)
return lowest
def highestScore():
highest = max(rdmScore)
return highest
def averageScore():
total = sum(rdmScore)
avg = float(total)/float(len(rdmScore))
return avg
print "Score (10 games): " + `rdmScore`
print "Average Score : " + `averageScore()`
print "Lowest Score : " + `lowestScore()`
print "Highest Score : " + `highestScore()`
[With Bonus]
from random import randint
def getScore():
rdmScore = []
for a in range(10):
rdmScore.append(randint(100,300))
return rdmScore
scoreList = getScore()
def lowestScore(scoreList):
lowest = min(scoreList)
return lowest
def highestScore(scoreList):
highest = max(scoreList)
return highest
def averageScore(scoreList):
total = sum(scoreList)
avg = float(total)/float(len(scoreList))
return avg
players = []
for i in range(5):
players.append(getScore())
for i in range(len(players)):
print "Player: " + `i+1`
print "Score (10 games): " + `players[i]`
print "Average Score : " + `averageScore(players[i])`
print "Highest Score : " + `highestScore(players[i])`
print "Lowest Score : " + `lowestScore(players[i])`
worst = 0
worstScore = averageScore(players[0])
for i in range(1,len(players)):
if averageScore(players[i]) < worstScore:
worst = i
worstScore = averageScore(players[i])
print "Worst player is : Player " + `worst+1`
print "His average score is " + `worstScore`
best = 0
bestScore = averageScore(players[0])
for i in range(1,len(players)):
if averageScore(players[i]) > bestScore:
best = i
bestScore = averageScore(players[i])
print "Best player is : Player " + `best+1`
print "His average score is " + `bestScore`
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment