with python Practice Exercise 4 O Write a program to request four inputs as foll
ID: 3750335 • Letter: W
Question
with python
Practice Exercise 4 O Write a program to request four inputs as follows. the name of a player (string type) the score of each stage int type) stage, and the average of stages O Then display the name of the player, the scores of each (rounded from 2 decimal places). Use 'format method' O Example) Enter the name of a player: Ann Enter the score of stage A: 1080 Enter the score of stage B: 754 Enter the score of stage C 130 aner ,0814,502 Average 1,080 754 1,302 ,045.33 Ann 0 digits 8 digits 8 digits 8 digits 10 digitsExplanation / Answer
# function for geting the input as name, score_a,score_b,score_c and then calculate the average
def get_score():
name=input("Enter the name of a player: ")
score_a = int(input("Enter the score of stage A: "))
score_b = int(input("Enter the score of stage B: "))
score_c = int(input("Enter the score of stage C: "))
avg = (score_b+score_a+score_c)/3
# return name, score_a,score_b,score_c and average
return name,score_a,score_b,score_c,avg
# function takes name, and three scores and avg
def show_score(name,a,b,c,avg):
# then print the head row
print(" Player | A | B | C | Average ")
# print first string value with width 10 and center adjusting, second, third, fourth value with width 8 and as comma seprated number,
# fifth value ascomma separated floating point number with width 10 and precision width limited to 2 digits
print("{:^10s}|{:^8,d}|{:^8,d}|{:^8,d}|{:^10,.2f} ".format(name,a,b,c,avg))
def main():
name,a,b,c,avg = get_score()
show_score(name,a,b,c,avg)
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.