Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I use the quantize function in python to round my answers to the nearest whole number? Can someone help me fix the code

How do I use the quantize function in python to round my answers to the nearest whole number? Can someone help me fix the code so I can get all my answers rounded to the nearest whole number? Also is it possible to take out duplicates in the answer?

Here is the code:

#importing xlwt library to write into xls import xlwt from xlwt import Workbook

#create a workbook wb = Workbook() #create a sheet sheet = wb.add_sheet('Sheet')

#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 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)) #calculate each percentage for j in range(len(percentages)): result = (percentages[j]/100)*val #write result to sheet by rounding upto 3 decimal points sheet.write(row,j+1,str(round(result,3))) #increment the row by 1 row+=1 #save Workbook as xls` wb.save('percentages.xls')

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

If [x + 2] = -3, what are the possible inputs for x?

Answered: 1 week ago

Question

1. What are the pros and cons of diversity for an organisation?

Answered: 1 week ago

Question

1. Explain the concept of diversity and equality in the workplace.

Answered: 1 week ago