PLEASE USE PYTHON 35 Also please make the two codes distinct

PLEASE USE PYTHON 3.5. Also please make the two codes distinct.

Thankyou!!

There are two programs ( A and B ).

PART A: Write all code in the main function:

make a dictionary for nine Tampa Bay Rays (see below). Use the player names as keys and a list for each value.

Each value list should hold the position played by the player, the batting order, and current batting average.

When the dictionary is complete, use a for loop to display the dictionary keys and values.

Next, use loop(s) to print the \"lineup\" (the dictionary in batting order). Duplicate the sample output for full points.

Pull Rivera and DeJesus. Substitute Wilson as catcher and Beckham as DH (see sample output).

Reprint the new lineup.

SAMPLE OUTPUT
Rays starters

DeJesus [\'DH\', 6, 299]
Loney [\'1B\', 4, 222]
Rivera [\'C\', 9, 194]
Forsythe [\'2B\', 5, 304]
Souza Jr [\'RF\', 2, 229]
Longoria [\'3B\', 3, 282]
Cabrera [\'SS\', 7, 214]
Kiermaier [\'CF\', 1, 240]
Guyer [\'LF\', 8, 274]

Today\'s lineup

Batting 1 : CF Kiermaier ,current avg: 240
Batting 2 : RF Souza Jr ,current avg: 229
Batting 3 : 3B Longoria ,current avg: 282
Batting 4 : 1B Loney ,current avg: 222
Batting 5 : 2B Forsythe ,current avg: 304
Batting 6 : DH DeJesus ,current avg: 299
Batting 7 : SS Cabrera ,current avg: 214
Batting 8 : LF Guyer ,current avg: 274
Batting 9 : C Rivera ,current avg: 194

Lineup changed

Batting 1 : CF Kiermaier ,current avg: 240
Batting 2 : RF Souza Jr ,current avg: 229
Batting 3 : 3B Longoria ,current avg: 282
Batting 4 : 1B Loney ,current avg: 222
Batting 5 : 2B Forsythe ,current avg: 304
Batting 6 : DH Beckham ,current avg: 200
Batting 7 : SS Cabrera ,current avg: 214
Batting 8 : LF Guyer ,current avg: 274
Batting 9 : C Wilson ,current avg: 152

PART B: Write all code in the main function:

create an empty set.

use a loop to add 10 random integers, all from 10 to 30 inclusive, to the set.

use another loop to process the set:

display all elements of the set on one line separated by ** (see sample outputs).

count how many elements are even and how many elements are odd.

display the counts.

SAMPLE OUTPUT
12**16**17**18**20**21**22**23**24**28**
Set has 7 even numbers and 3 odd numbers

SAMPLE OUTPUT
10**12**14**16**18**20**21**22**25**26**
Set has 8 even numbers and 2 odd numbers

Solution

Part A:

Code:


def print_lineup(d):
   v = list(d.values())
   k = list(d.keys())
   for j in range(len(v)):
       for i in range(len(v)):
           order = v[i][1]
           if(j+1 == order):
               valHere = v[i]
               keyHere = (k[v.index(valHere)])
               print(\"Batting %d: %s %s , current Avg: %d\"%(j+1,valHere[0],keyHere,valHere[2]))

def update_dict(d, oldKey, newKey):
   newVal1 = d[oldKey]
   d.pop(oldKey)
   d1 = {newKey:newVal1}
   d.update(d1)

d = {\"DeJesus\":[\'DH\', 6, 299], \"Loney\":[\'1B\', 4, 222], \"Rivera\":[\'C\', 9, 194],\"Forsythe\": [\'2B\', 5, 304],\"Souza Jr\": [\'RF\', 2, 229],\"Longoria\": [\'3B\', 3, 282],\"Cabrera\": [\'SS\', 7, 214],\"Kiermaier\": [\'CF\', 1, 240],\"Guyer\": [\'LF\', 8, 274]}
duplicate = {}
print(\"Today\'s Lineup\ \")
print_lineup(d)

print(\"\ Lineup Changed\")      
d1 = d.copy()          
update_dict(d1,\"Rivera\",\"Wilson\")
update_dict(d1,\"DeJesus\",\"Beckham \")
print_lineup(d1)      

Output:

Part B:

Code:

import random
a = []
for i in range(10):
   n = random.randint(10,30)
   a.append(n)

odd = 0
even = 0
for i in range(10):
   if(a[i] % 2 == 0):
       even+=1
   else:
       odd+=1
      
for i in range(10):
   print(\"%d**\"%a[i])
  
print(\"Set has %d even numbers and %d odd numbers\"%(even,odd))  

Output:

PLEASE USE PYTHON 3.5. Also please make the two codes distinct. Thankyou!! There are two programs ( A and B ). PART A: Write all code in the main function: make
PLEASE USE PYTHON 3.5. Also please make the two codes distinct. Thankyou!! There are two programs ( A and B ). PART A: Write all code in the main function: make
PLEASE USE PYTHON 3.5. Also please make the two codes distinct. Thankyou!! There are two programs ( A and B ). PART A: Write all code in the main function: make

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site