Find answers to your most challenging questions with the help of IDNLearn.com's experts. Find accurate and detailed answers to your questions from our experienced and dedicated community members.

(PYTHON) Complete the program to print out nicely formatted football player statistics. Match the following output as closely as possible -- the ordering of players is not important for this example.
2012 quarterback statistics:
Passes completed:
Greg McElroy : 19
Aaron Rodgers : 371
Peyton Manning : 400
Matt Leinart : 16
Passing yards: ...
Touchdowns / Interception ratio:
Greg McElroy : 1.00
Aaron Rodgers : 4.88
Peyton Manning : 3.36
Matt Leinart : 0.00
quarterback_stats = {
'Aaron Rodgers': {'COMP': 371, 'YDS': 4925, 'TD': 39, 'INT': 8},
'Peyton Manning': {'COMP': 400, 'YDS': 4659, 'TD': 37, 'INT': 11},
'Greg McElroy': {'COMP': 19, 'YDS': 214, 'TD': 1, 'INT': 1},
'Matt Leinart': {'COMP': 16, 'YDS': 115, 'TD': 0, 'INT': 1}
}

print('2012 quarterback statistics:')

print(' Passes completed:')
for qb in quarterback_stats:
comp = quarterback_stats[qb]['COMP']
#print(' %?: %?' % (qb, comp)) # Replace conversion specifiers
# Hint: Use the conversion flag '-' to left-justify names

print(' Passing yards:')
for qb in quarterback_stats:
print(' QB: yards')

print(' Touchdown / interception ratio:')
# ...
# Hint: Convert TD/INTs to float before calculating ratio


Sagot :

Answer:

quarterback_stats = {

'Aaron Rodgers': {'COMP': 371, 'YDS': 4925, 'TD': 39, 'INT': 8},

'Peyton Manning': {'COMP': 400, 'YDS': 4659, 'TD': 37, 'INT': 11},

'Greg McElroy': {'COMP': 19, 'YDS': 214, 'TD': 1, 'INT': 1},

'Matt Leinart': {'COMP': 16, 'YDS': 115, 'TD': 0, 'INT': 1}

}

print("2012 quaterback statistics: ")

print("Passes completed: ")

for qb in quaterback_stats.keys():

   print(f"{quaterback_stats[qb]} : {quaterback_stats[qb]['COMP']}")

print("Passing yards:")

for qb in quaterback_stats.keys():

   print(f"{quaterback_stats[qb]} : {quaterback_stats[qb]['YDS']}")

print("Touchdown / interception ratio")

for qb in quaterback_stats.keys():

   if quaterback_stats[qb]['TD'] > 0 and quaterback_stats[qb]['INT'] > 0:

       print(f"{quaterback_stats[qb]} : {float(quaterback_stats[qb]['TD']) / float(quaterback_stats[qb]['INT])}")

   else:

       print(f"{quaterback_stats[qb]} : {0.0}")

Explanation:

The python program gets data from a dictionary called quaterback_stats which holds the data of football players with their names as the keys and a list of records as the value.

The program prints the individual records from the dictionary using a for loop statement on the list of dictionary keys (using the keys() method).

We value your presence here. Keep sharing knowledge and helping others find the answers they need. This community is the perfect place to learn together. IDNLearn.com is your source for precise answers. Thank you for visiting, and we look forward to helping you again soon.