Question

PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv (PLEASE TYPE OUT ANSWER) Modify this program:...

PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv (PLEASE TYPE OUT ANSWER)

Modify this program:

Write a program to calculate the bmi
getcategory(): takes the bmi as a parameter and returns the bmi category.

You are not allowed to change the two functions and you will use the same two functions as previously. Just modify the program so that it calculates the bmi and category for any number of pairs of height and weights. You must loop through the height and weights, calling the functions, for full credit. The error message should still work the same as in the previous assignment. If someone enters the wrong number of arguments (see below), a different error message appears. The output is shown below.

Input:

a) 65 120 70 170

b) 65 120 70

Output:

a) BMI: 19.97, and the category is normal.
BMI: 24.39, and the category is normal.

b) The wrong number of arguments provided.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<<<<<<<<<<<<<python 3>>>>>>>>>>>>>>>>>>>>>>>>>>

import sys

def checkdata(input1):
   try:
       input1=[float(i) for i in input1]
       return True
   except:
       return False
   return False

def calcbmi(height, weight):
bmi=(weight * 703) / (height ** 2)
return round(bmi,2)

def getcategory(bmi):
# Conditions to find out BMI category
if (bmi < 18.5):
category="Underweight"
elif ( bmi >= 18.5 and bmi < 24.9):
category="Normal"
elif ( bmi >= 24.9 and bmi < 30):
category="Overweight"
elif ( bmi >=30):
category="Obese"
  
return category

num=len(sys.argv)
input1=sys.argv[1:]

if (num%2==0):
   print("The wrong number of arguments provided.")
else:
   if checkdata(input1):
       for i in range(0, len(input1),2):
           height = float(input1[i])
           weight = float(input1[i+1])
           bmi = calcbmi(height, weight)
           print("BMI : ", bmi," and the category is ",getcategory(bmi))
   else:
       print('only numbers are allowed')

<<<<<<<<<<<<<<<<<<<<<<<<<< sample output>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Add a comment
Know the answer?
Add Answer to:
PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv (PLEASE TYPE OUT ANSWER) Modify this program:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A. Write a Python script so that the user can enter any number of grades. Create...

    A. Write a Python script so that the user can enter any number of grades. Create a calcavg() function so that it takes the number of grades as a parameter and returns the regular average (not a weighted average). You must loop through the grades for full credit. Add a try/except block so that if a non-numeric value is entered, you get the error message shown below. You cannot use lists. Input: c. python …\IT2430\FirstLastname\assign5-2.py 96.7 95.6 87.0 d. python...

  • DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...

    DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a function called inch2cm that takes one number in inches as a parameter, converts it to the centimeters and prints the result. The program output is shown below. Input: 14 Output: 14 inches = 35.56 centimeter Write a program and create the following functions: shapes(): takes the shape name and a number as parameters, and calls the proper function to calculate the area. areaCircle(): take...

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

  • Please solve the following, please type out the code, and do not hand write because its...

    Please solve the following, please type out the code, and do not hand write because its hard to read. I would greatly appreciate it. (JAVA) Problem 1 In a class called H1P1, write a method called bmiOne that takes as arguments a mass in kilograms (a double) and a height in meters (also a double), and returns the body mass index (or BMI) for the given data. If we have mass -m kg and height-h meters, then BMI = Write...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates th...

    read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates the BMI using the equation below, displays the BMI category, and outputs the BMI value tothe user's program W (kg) h2 (m2) BMI Display Normal if 18.5 s BMI 25 Display Overweight if 25 s BMI <30 Display Obese if BMI 2 30 Else display underweight So you will create two...

  • Python Please. a)Let a program store the result of applying the eval function to the first...

    Python Please. a)Let a program store the result of applying the eval function to the first command-line argument. Print out the resulting object and its type. Run the program with different input: an integer, a real number, a list, and a tuple. (On Unix systems you need to surround the tuple expressions in quotes on the command line to avoid error message from the Unix shell.) Try the string "this is a string" as a commandline argument. Why does this...

  • Lab Assignment 4B Modify your program in Lab Assignment 4A to throw an exception if the...

    Lab Assignment 4B Modify your program in Lab Assignment 4A to throw an exception if the file does not exist. An error message should result.   Use the same file name in your program as 4A, however, use the new input file in 4B assignment dropbox. Lab 4A: Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. Test with...

  • Write a function which asks users to enter names, heights, and weights of eachperson. For simplicity,...

    Write a function which asks users to enter names, heights, and weights of eachperson. For simplicity, let's assume names contain no white space - for example, justfirst names like John, Mike or Luke (so you can use cin >> name to get the name).Also assume height will range from 1.3 to 2.0 meters (which means if someoneenters a height that is less than 1.3 or greater than 2.0, show an error message andkeep asking user to enter them until they...

  • Lab 1: InheritanceTest Write a program called InheritanceTest1.java to support an inheritance hierarchy for class Point–Square–Cube....

    Lab 1: InheritanceTest Write a program called InheritanceTest1.java to support an inheritance hierarchy for class Point–Square–Cube. Use Point as the superclass of the hierarchy. Specify the instance variables and methods for each class. The private data of Point should be the x-y coordinates, the private data of Square should be the sideLength, and the private data of Cube should be depth. Provide applicable accessor methods, mutator methods, toString() methods, area() method, and volume() method to all classes. Write a program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT