Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

However when i run the code it gives me this error: File /Users/../Desktop/proj1/exaple.py lint 88, in ChooseOrdering if abs(sum(ascending) - sum(descending)) < 0.00001: TypeError: unsupported

However when i run the code it gives me this error:

File "/Users/../Desktop/proj1/exaple.py lint 88, in ChooseOrdering if abs(sum(ascending) - sum(descending)) < 0.00001:

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

PYTHON

def OrderCurriences(fp, fp_out=sys.stdout): ascending = [] descending = []

for line in fp: line = line.replace("," , "") l = [] copylist = [] l.append(line) # appends list into array copylist.append(line) # appends list into copyarray (same array that comes from file) m = mergeSort(l) ascending.append(m) #inversion counts gets appended into the array each time a line goes through n = DSort(copylist) descending.append(n) ChooseOrdering(ascending,descending,fp_out=sys.stdout) #returns inversion counts to function

pass

def main(): fp = open(input("Insert Filename (with extension) for input: ").strip())

fp_out = open(input("Insert Filename (with extension) for output: ").strip(), 'w')

OrderCurriences(fp, fp_out) fp_out.close()

# OrderCurriences(fp)

# fp.close()

main()

def ChooseOrdering(ascending, descending, fp_out=sys.stdout)

if abs(sum(ascending) - sum(descending)) < 0.00001: outcome = "TIE" else: outcome = "ASCENDING" if sum(ascending) < sum(descending) else "DESCENDING"

# directing output to file print("Total Number of portfolio's assessed: ", len(ascending), file=fp_out) print(" " * 12, "{:^12s} vs {:^12s}".format("Ascending", "Descending"), file=fp_out) for pairs in range(len(ascending)): print("Portfolio #{:02d} {:^12d} vs {:^12d}" \ .format(pairs + 1, ascending[pairs], descending[pairs]), file=fp_out) print(" Total Inversion Count", file=fp_out) print("Ascending: ", sum(ascending), " vs. Descending: ", sum(descending), file=fp_out)

print(" Best Form of Ordering: ", outcome, file=fp_out)

File:

testcase00.txt

1,2,3 0,0,0 2,3,2,1,5 5,4,3,2,1

HELP IM NOT SURE WHAT IS WRONG

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions