def punctuate(sentence, phrase_type):
if phrase_type == "exclamation":
sentence_punct = sentence + "!"
elif phrase_type == "question":
sentence_punct = sentence + "?"
elif phrase_type == "aside":
sentence_punct = "(" + sentence + ".)"
else:
sentence_punct = sentence + "."
return sentence_punct
def cylinder_surface_area(radius, height, has_top_and_bottom):
side_area = height * 6.28 * radius
if has_top_and_bottom:
top_area = 3.14 * radius ** 2
return top_area + side_area
else:
return side_area
errors = 3
if errors:
print("There are " + errors + " mistakes. Please correct.")
else:
print("No mistakes here!")
def convert_to_numeric(score):
"""
Convert the score to a numerical type.
"""
converted_score = float(score)
return converted_score
def sum_of_middle_three(score1,score2,score3,score4,score5):
"""
Find the sum of the middle three numbers out of the five given.
"""
max_score = max(score1,score2,score3,score4,score5)
min_score = min(score1,score2,score3,score4,score5)
sum = score1 + score2 + score3 + score4 + score5 - max_score - min_score
return sum
def score_to_rating_string(score):
if score < 1:
return "Terrible"
elif score < 2:
return "Bad"
elif score < 3:
return "OK"
elif score < 4:
return "Good"
elif score <= 5:
return "Excellent"
else:
return "nothing"
def scores_to_rating(score1,score2,score3,score4,score5):
score1 = convert_to_numeric(score1)
score2 = convert_to_numeric(score2)
score3 = convert_to_numeric(score3)
score4 = convert_to_numeric(score4)
score5 = convert_to_numeric(score5)
#STEP 2 and STEP 3 find the average of the middle three scores
average_score =
sum_of_middle_three(score1,score2,score3,score4,score5)/3
#STEP 4 turn average score into a rating
rating = score_to_rating_string(average_score)
return rating