Design the logic for a program needed by the manager of the
Design the logic for a program needed by the manager of the Stengel County softball team,who wants to compute slugging percentages for his players.A slugging percentage is the total bases earned with base hits divided by the player\'s number of at-bats. Design a program that prompts the user for a player jersey number,the number of bases earned,and the number of at-bats, and then displays all the data,including the calculated slugging average.The program accepts players continuously until 0 is entered for the jersey number. b. Modify the slugging percentage program to also calculate a player\'s on base percentage.An on base percentage is calculated by adding a player\'s hits and walks,and then dividing by the sum of at-bats,walks, and sacrifice flies.Prompt the user for all the additional data needed,and display all the data for each player.
Solution
Logic
1)
while (true){
INPUT int jersey_number;
IF jersey_number == 0{ break; }
DECLARE slugging_percentage;
INPUT int total_bases;
INPUT int at_bats;
slugging_percentage = total_bases/at_bats;
OUTPUT jersey_number, total_bases, at_bats, slugging_percentage
}
2)
while (true){
INPUT int jersey_number;
IF jersey_number == 0{ break; }
DECLARE onbase_percentage;
DECLARE slugging_percentage;
INPUT int total_bases;
INPUT int at_bats;
INPUT int hits;
INPUT int walks;
INPUT sacrifice_flies;
slugging_percentage = total_bases/at_bats;
onbase_percentage = (hits + walks)/(at_bats+walks+sacrifice_flies);
OUTPUT string jersey_number, total_bases, at_bats, slugging_percentage, onbase_percentage;
}
Python code
1)
while (True):
jersey_number = input(\"Jersey Number: \")
if jersey_number == 0:
break
total_bases = input(\"Total bases: \")
at_bats = input(\"At bats: \")
slugging_percentage = 1.0*total_bases/at_bats;
print \"Jersey Number:\", jersey_number, \"Total Bases:\", total_bases, \"At Bats:\", at_bats, \"Slugging Percentage: \",slugging_percentage
2)
while (True):
jersey_number = input(\"Jersey Number: \")
if jersey_number == 0:
break
total_bases = input(\"Total bases: \")
at_bats = input(\"At bats: \")
hits = input(\"Hits: \")
walks = input(\"Walks: \")
sacrifice_flies = input(\"Sacrifice Flies: \")
slugging_percentage = 1.0*total_bases/at_bats;
onbase_percentage = (hits + walks)/(at_bats+walks+sacrifice_flies);
print \"Jersey Number:\", jersey_number, \"Total Bases:\", total_bases, \"At Bats:\", at_bats, \"Slugging Percentage: \",slugging_percentage

