Question

In: Computer Science

Using Python write the following script as well as using comments By considering the details below,...

Using Python write the following script as well as using comments

By considering the details below, write a class that will work out the body mass index for specific values of weight and height. The design of the actual class is shown below:

bmi

-weight:float

-height:float

-bmi:float

+set_weight(weight:float)

+set_height(height:float)

+calc_bmi()

+get_bmi():float

specific designs of the methods are shown below:

set_weight

set the weight attribute to the value in the parameter weight

set_height

set the height attribute to the value in the parameter height

calc_bmi

calculate Bmi using the formula: bmi=weight/(height/100)**2

get_bmi

return the value stored in the bmi attribute

After creating the class write a main function that will create an instance of the class and test the implementation.

Solutions

Expert Solution

#class named as bmi
class bmi:
#constructor
#It is required so as to initialize instance variable
def __init__(self):
#set all variables to 0
self.weight=0.0
self.height=0.0
self.bmi=0.0
#function to set weight
def set_weight(self,weight):
#setting weight to parameter
self.weight=weight
#function to set height
def set_height(self,height):
#setting height to parameter value
self.height=height
#function for calculation of bmi
def calc_bmi(self):
#using given formula to calculate bmi and store in self.bmi
self.bmi=self.weight/(self.height/100)**2
#getter for bmi
def get_bmi(self):
#return the value of self.bmi
return self.bmi
#implementation
#creating an instance of bmi class which is BMI
BMI=bmi()
#calling setter for weight to set weight of instance BMI to 70
BMI.set_weight(70)
#calling setter for height to set height of instance BMI to 180 cm
BMI.set_height(180)
#function to calculate bmi
BMI.calc_bmi()
#printing the returned value from the getter for bmi
#%.2f is used to print 2 digits after decimal point
print("Body Mass Index: %.2f"%BMI.get_bmi())
  


Related Solutions

#python. Explain code script of each part using comments for the reader. The code script must...
#python. Explain code script of each part using comments for the reader. The code script must work without any errors or bugs. Ball moves in a 2D coordinate system beginning from the original point (0,0). The ball can move upwards, downwards, left and right using x and y coordinates. Code must ask the user for the destination (x2, y2) coordinate point by using the input x2 and y2 and the known current location, code can use the euclidean distance formula...
Write the following Python script: Pikachu is a well-known character in the Pokemon anime series. Pikachu...
Write the following Python script: Pikachu is a well-known character in the Pokemon anime series. Pikachu can speak, but only 3 syllables: "pi", "ka", and "chu". Therefore Pikachu can only pronounce strings that can be created as a concatenation of one or more syllables he can pronounce. For example, he can pronounce the words "pikapi" and "pikachu". You are given a String word. Your task is to check whether Pikachu can pronounce the string. If the string can be produced...
PYTHON: Write a script that imports the functions in the module below and uses all of...
PYTHON: Write a script that imports the functions in the module below and uses all of the functions. import math def _main():     print("#" * 28, "\n", "Testing...1, 2, 3...testing!\n", "#" * 28, "\n", sep="")     f = -200     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     f = 125     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     c = 0     print("{:.2f} C is {:.2f} F".format(c, c2f(c)))     c = -200     print("{:.2f} C is {:.2f} F".format(c, c2f(c))) def f2c(temp):     #Converts Fahrenheit tempature to Celcius     if temp <...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments...
Please write python code for the following. Implement the functions defined below. Include a triple-quoted comments string at the bottom displaying your output. Using sets (described in Deitel chapter 6) will simplify your work. Below is the starter template for the code: def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2 have in common """ return 0    def most_similar(user, interests): """ Determine the name of user who is most similar to the input user...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Solve using PYTHON PROGRAMMING 9. Write a script that reads a file “ai_trends.txt”, into a list...
Solve using PYTHON PROGRAMMING 9. Write a script that reads a file “ai_trends.txt”, into a list of words, eliminates from the list of words the words in the file “stopwords_en.txt” and then a. Calculates the average occurrence of the words. Occurrence is the number of times a word is appearing in the text b. Calculates the longest word c. Calculates the average word length. This is based on the unique words: each word counts as one d. Create a bar...
Solve using PYTHON PROGRAMMING Write a script that reads a file “cars.csv”, into a pandas structure...
Solve using PYTHON PROGRAMMING Write a script that reads a file “cars.csv”, into a pandas structure and then print a. the first 3 rows and the last 3 of the dataset b. the 3 cars with the lowest average-mileage c. the 3 cars with the highest average-mileage. Solve using PYTHON PROGRAMMING
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a variable str1. Use the eval() function to evaluate str1and assign the result to a variable num1. Ask the user to input their birth month and assign it to a variable month and then print it with a suitable message. Determine the number of letters in month and display the result with a suitable message. Determine how many times the letter 'r ' occurs in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT