Question

1. You will develop a Python program to manage information about baseball players. The program will...

1. You will develop a Python program to manage information about baseball players. The program will maintain the following information for each player in the data set:

player’s name (string)

team identifier (string)

games played (integer)

at bats (integer)

runs scored (integer)

hits (integer)

doubles (integer)

triples (integer)

homeruns (integer)

batting average (real)

slugging percentage (real)

The first nine items will be taken from a data file; the last two items will be computed by the program. The following formulas will be used for those computations:

singles = hits - (doubles + triples + homeruns)

total bases = singles + 2*doubles + 3*triples + 4*homeruns

batting average = (hits) / (at bats)

slugging percentage = (total bases) / (at bats)

A player with zero at bats is defined to have a batting average and slugging percentage of zero

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python code:

#Taking input for the baseball players from the user input
player_name=input('Enter player name:')
team_identifier=input('Enter Team id:')
games=int(input('Number of games played:'))
at_bats=int(input('Number of at bats played:'))
runs=int(input('runs scored:'))
hits=int(input('Number of hits:'))
doubles=int(input('Number of doubles:'))
triples=int(input('Number of triples:'))
homeruns=int(input('Number of homeruns:'))

#singles formula
singles=((hits)-(doubles)+(triples)+(homeruns))
#total_bases formula
total_bases=((singles) + (2*doubles) + (3*triples) + (4*homeruns))

#if_else condition
if at_bats==0: #condition 1
batting_avg=0
slug_perc=0
print('Batting average',batting_avg)
print('Slug percentage',slug_perc)
else: #condition 2
batting_avg=float((hits)/(at_bats))
slug_perc=float((total_bases)/at_bats)
print('Batting average',batting_avg)
print('Slug percentage',slug_perc)

Image reference:

programme.py - C:/Users/Nagendra Babu/Desktop/programme.py (3.7.0) File Edit Format Run Options Window Help #Taking input for

Output:

Python 3.7.0 Shell File Edit Shell Debug Options Window Help Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1

Python 3.7.0 Shell File Edit Shell Debug Options Window Help Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1

Add a comment
Know the answer?
Add Answer to:
1. You will develop a Python program to manage information about baseball players. The program will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In baseball, a players a players slugging percentage is calculated by assigning a weight of 1...

    In baseball, a players a players slugging percentage is calculated by assigning a weight of 1 to singles, 2 to doubles, 3 to triples, and 4 to home runs. After adding these values together, you divide by the number of at-bats. Find the slugging percentage for the following player: (Data given in image) Slugging percentage: _____ In baseball, a player's slugging percentage is calculated by assigning a weight of 1 to singles, 2 to doubles, 3 to triples, and 4...

  • write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on...

    write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on a team. Team name, player name, and player position will also be input.(two dimensional array) The program should then calculate and print the individual batting average and, after all 9 players have been entered, calculate and print the team batting average. Example of inputs and Outputs... Enter the Team name: (one time entry)...

  • c++ A menu-driven program gives the user the option to find statistics about different baseball players....

    c++ A menu-driven program gives the user the option to find statistics about different baseball players. The program reads from a file and stores the data for ten baseball players, including player’s team, name of player, number of homeruns, batting average, and runs batted in. (You can make up your data, or get it online, for example: http://espn.go.com/mlb/statistics ) Write a program that declares a struct to store the data for a player. Declare an array of 10 components to...

  • Create a struct for a baseball player. Include the player's Name (string), Batting Average (percentage), Home...

    Create a struct for a baseball player. Include the player's Name (string), Batting Average (percentage), Home Runs (int), RBI's (int), Runs Scored (int), Stolen bases (int), current salary (float) and current team (string). Create three players using your struct and then display the stats from each player to the screen using the members of the struct- three extra credit points for doing this for all members of the struct in a function.

  • Option #1: Batting The batting average of a baseball player is the number of “hits” divided by the number of “at-bats.”...

    Option #1: Batting The batting average of a baseball player is the number of “hits” divided by the number of “at-bats.” Recently, a certain major league player’s at-bats and corresponding hits were recorded for 200 consecutive games. The consecutive games span more than one season. Since each game is different, the number of at-bats and hits both vary. For this particular player, there were from zero to five at-bats. Thus, one can sort the 200 games into six categories: 0...

  • The batting average of a baseball player is the number of “hits” divided by the number of “at-bats.” Recently, a certain...

    The batting average of a baseball player is the number of “hits” divided by the number of “at-bats.” Recently, a certain major league player’s at-bats and corresponding hits were recorded for 200 consecutive games. The consecutive games span more than one season. Since each game is different, the number of at-bats and hits both vary. For this particular player, there were from zero to five at-bats. Thus, one can sort the 200 games into six categories: 0 at-bats 1 at-bat...

  • Jeff Sagarin has been providing sports ratings for USA Today since 1985. In baseball, his predicted...

    Jeff Sagarin has been providing sports ratings for USA Today since 1985. In baseball, his predicted RPG (runs per game) statistics considers the entire player’s offensive statistics and is claimed to be the best measure of a player’s true offensive value. A set of sample data was collected for RPG and a variety of offensive statistics for a recent Major League Baseball (MLB) season for members of the New York Yankees. The variables are defined as follows: RPG, predicted runs...

  • Jeff Sagarin has been providing sports ratings for USA Today since 1985. In baseball, his predicted...

    Jeff Sagarin has been providing sports ratings for USA Today since 1985. In baseball, his predicted RPG (runs per game) statistics considers the entire player’s offensive statistics and is claimed to be the best measure of a player’s true offensive value. A set of sample data was collected for RPG and a variety of offensive statistics for a recent Major League Baseball (MLB) season for members of the New York Yankees. The variables are defined as follows: RPG, predicted runs...

  • Chapter 8 Python Case study Baseball Team Manager For this case study, you’ll use the programming...

    Chapter 8 Python Case study Baseball Team Manager For this case study, you’ll use the programming skills that you learn in Murach’s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. After you read chapter 2, you can develop a simple program that calculates the batting average for a player. Then,...

  • Chapter 05 Case study Baseball team For this case study, you’ll use the programming skills that...

    Chapter 05 Case study Baseball team For this case study, you’ll use the programming skills that you learn in Murach’s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. After you read chapter 2, you can develop a simple program that calculates the batting average for a player. Then, after you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT