Menu

Someone Remove Duplicate Numbers Excluding 1 Column Percentage Row Percentage Row Top 1st Q43789664

can someone remove all duplicate numbers excluding the1 column and percentage row only. percentage row is on the top and1st column is entered numbers.

Here’s the code:

import xlwt
from xlwt import Workbook
from decimal import *

#create a workbook
wb = Workbook()
#create a sheet
sheet = wb.add_sheet(‘Sheet’,cell_overwrite_ok=True)

#percentages list
percentages = [23.6, 38.2, 50, 61.8, 78.6, 113, 123.6, 138.2,161.8]
#add first row
for i in range(len(percentages)):
sheet.write(0,i+1,str(percentages[i])+’%’)

#user input
n = int(input(‘Enter number of elements: ‘))
#second row starts from index 1
row=1
#created dictionary to store elements entered in first column ofexcel sheet
storeCol_dict ={}
print(‘Enter numbers: ‘)
for i in range(n):
#User input
val = float(input())

#Add entered value to first column of the row
sheet.write(row,0,str(val))
#after value is written at first column
#check if it exists in the dictionary declared above
#if yes, then increment row and continue the loop as no need tocalculate values again
#so that no duplicate rows are there
if val in storeCol_dict:
row+=1
continue

#add element to dictionary and let’s have its value asany number, here it’s 1
storeCol_dict[val] = 1;
#calculate each percentage
prev = “”
for j in range(len(percentages)):
result = (percentages[j]/100)*val
#write result to sheet by rounding to nearest whole number usingquantize method
current = str(Decimal(result).quantize(Decimal(“1”)))
if(prev != current):
sheet.write(row,j+1,current)
prev = current
#indentation is corrected here so that this statement comes underfirst for loop   
#increment the row by 1
row+=1
#save Workbook as xls`
wb.save(‘percentages.xls’)

thanks to anyone who helped!

Expert Answer


Answer to can someone remove all duplicate numbers excluding the 1 column and percentage row only. percentage row is on the top an…

OR