66.6k views
4 votes
2.13) A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height and 5 pounds for each additional inch. Write a program that reads the data in the file and outputs the full name and ideal body weight for each person. In the next chapter, you will learn about loops, which allow for a more efficient way to solve this problem.

User Goktug
by
4.4k points

1 Answer

3 votes

Answer:

import csv

def ideal_weight( filename ):

with open( "filename", "r" ) as file:

for row in csv.DictReader( file):

print ( "Name of person: ",row["name"] )

person_weight = ( 110 * row["height"] )/ 5

print ( "Ideal weight: ", person_weight )

Step-by-step explanation:

The python source code above is a function which recieves a csv file argument, opens the file and reads each row an ordered dictionary. The function prints the name of each person in the file and their ideal weight.

User Sander Toonen
by
3.6k points