# (Solved Homework): In python 3, how do I upload a txt file and manipulate it so that the file gives an average, max, and min and how do I

In python 3, how do I upload a txt file and manipulate it so that the file gives an average, max, and min and how do I add a new column to the txt file? The txt file is below and is called “data” and gives the name, height, and weight. How do I add a new column for BMI which is weight/(height^2) and find the average, max, and min for the columns? The first image is what the txt file gives and the second image is what the python code is suppose to give and look like.

#!/usr/local/bin/python3

# program to calculate BMI

def main():
# opening the file out.txt for writing the output
outfile = open(“output.txt”, “w”)

# opening the file data.txt for reading
with open(“data.txt”) as fp:
# initializing the variables
(max_weight, min_weight, sum_weight, avg_weight) = (0, 10**9, 0, 0)
(max_height, min_height, sum_height, avg_height) = (0, 10**9, 0, 0)
(max_bmi, min_bmi, sum_bmi, avg_bmi) = (0, 10**9, 0, 0)
n = 0
for line in fp:
# printing the header
if ‘Name’ in line:
print (“{:<12s} {:<12s} {:<12s} {:<12s}”.format(‘Name’, ‘Height(m)’, ‘Weight(kg)’, ‘BMI’), file=outfile)
else:
# splitting the line from file and storing into variables
(name, height, weight) = line.split()

# converting weight and height as float variables
weight = float(weight)
height = float(height)

# identify max and min from the weight numbers
if weight > max_weight:
max_weight = weight
if weight < min_weight:
min_weight = weight
sum_weight = sum_weight + weight

# identifying max and min from the height numbers
if height > max_height:
max_height = height
if height < min_height:
min_height = height
sum_height = sum_height + height

# calculating bmi and identifying min and max from the bmi numbers
bmi = weight / height ** 2
if bmi > max_bmi:
max_bmi = bmi
if bmi < min_bmi:
min_bmi = bmi
sum_bmi = sum_bmi + bmi

n = n + 1
print (“{:<12s} {:<12.2f} {:<12.2f} {:<12.2f}”.format(name, height, weight, bmi), file=outfile)

# calculating average weight, height and bmi
avg_weight = sum_weight / n
avg_height = sum_height / n
avg_bmi = sum_bmi / n
print (“n”, file=outfile)

# printing average, max, min statistics
print (“{:<12s} {:<12.2f} {:<12.2f} {:<12.2f}”.format(‘Average’, avg_height, avg_weight, avg_bmi), file=outfile)
print (“{:<12s} {:<12.2f} {:<12.2f} {:<12.2f}”.format(‘Max’, max_height, max_weight, max_bmi), file=outfile)
print (“{:<12s} {:<12.2f} {:<12.2f} {:<12.2f}”.format(‘Min’, min_height, min_weight, min_bmi), file=outfile)

fp.close()
outfile.close()

if __name__==’__main__’:
main()

Order NOW for a 10% Discount
Pages (550 words)
Approximate price: -

Why Us?

Top Quality and Well-Researched Papers

All ourbpapers are written from scratch. In fact, Clients who ask for paraphrasing services are highly discouraged. We have writers ready to craft any paper from scratch and deliver quality ahead of time.

Professional and Experienced Academic Writers

Our writers keeps you posted on your papers progress - providing you with paper outline/draft. You are also at liberty to communicate directly with your writer.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time, in many cases quite ahead of time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Follow these simple steps to get your paper done

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

## Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.