Switching cities python code knowledge required PLEASE PROVIDE SCREEN SHOTS OF C
ID: 3812612 • Letter: S
Question
Switching cities python code knowledge required PLEASE PROVIDE SCREEN SHOTS OF CODE FOR THIS PROBLEM I HAVE COMPLETED PART OF THE CODE FOR YOU JUST FILL IN THE PORTION OF CODE THATS NEEDED FOR goodfeedback thanks
import sys
def cities(months, switchingCost, profitInCity1, profitInCity2):
#
# Please write code here
#
profit = 0
cityList = [1 for i in range(months)]
return profit,cityList
# Read input
header = sys.stdin.readline().strip(' ').split(' ')
city1 = sys.stdin.readline().strip(' ').split(' ')
city1 = [int(x) for x in city1]
city2 = sys.stdin.readline().strip(' ').split(' ')
city2 = [int(x) for x in city2]
profit,cityList = cities(int(header[0]), int(header[1]), city1, city2)
listString = ' '.join(str(x) for x in cityList)
print profit # max profit
print listString # cities
Explanation / Answer
import sys
def cities(months, switchingCost, profitInCity1, profitInCity2):
#
# Please write code here
#
profit = 0
cityList = [1 for i in range(months)]
for i in range(0,len(profitInCity1)):
if profitInCity1[i] < profitInCity2[i]:
profit =profit+profitInCity2;
cityList.append(1);
else:
profit = profit+profitInCity1;
cityList.append(1);
return profit,cityList;
# Read input
header = sys.stdin.readline().strip(' ').split(' ')
city1 = sys.stdin.readline().strip(' ').split(' ')
city1 = [int(x) for x in city1]
city2 = sys.stdin.readline().strip(' ').split(' ')
city2 = [int(x) for x in city2]
profit,cityList = cities(int(header[0]), int(header[1]), city1, city2)
listString = ' '.join(str(x) for x in cityList)
print profit # max profit
print listString # cities
Note: Indensation is very important.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.