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...

  • I need help with this Java problem, please. Code must be written in Java Create an...

    I need help with this Java problem, please. Code must be written in Java Create an application that calculates batting statistics for baseball players. Console Welcome to the Batting Average Calculator Enter number of times at bat: 5 0 = out, 1 = single, 2 = double, 3 = triple, 4 = home run Result for at-bat 1: 0 Result for at-bat 2: 1 Result for at-bat 3: 0 Result for at-bat 4: 2 Result for at-bat 5: 3 Batting...

  • Help me figure this problem out, please. Use a list to store the players Update the...

    Help me figure this problem out, please. Use a list to store the players Update the program so that it allows you to store the players for the starting lineup. This should include the player’s name, position, at bats, and hits. In addition, the program should calculate the player’s batting average from at bats and hits. Console ================================================================ Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5...

  • 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.

  • Case Study Baseball Team Manager For this case study, you’ll use the programming skills that you...

    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, after you complete...

  • 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...

  • In Java For the following questions, “define a class” means the following: • Create an appropriately-named...

    In Java For the following questions, “define a class” means the following: • Create an appropriately-named file containing the Java class definition, including the following: – A block comment describing the file (and hence the class), as always – Any instance variables, as required by the question – Accessor (getter) and mutator (setter) methods for any instance variables – Constructors as appropriate or as required by the question – A toString method that prints instances of the class informatively –...

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