Knowee
Questions
Features
Study Tools

Traceback (most recent call last): File "main.py", line 8, in <module> bmi = height / (weight * weight)TypeError: can't multiply sequence by non-int of type 'str'

Question

Traceback (most recent call last): File "main.py", line 8, in <module> bmi = height / (weight * weight)TypeError: can't multiply sequence by non-int of type 'str'

🧐 Not the exact question you are looking for?Go ask a question

Solution

The error message you're seeing is a Python error. It's telling you that you're trying to multiply a string data type, which isn't possible.

In the line bmi = height / (weight * weight), either height or weight or both are string(s). You need to convert these to a numerical data type (like int or float) before performing mathematical operations on them.

Here's how you can do it:

height = float(height)
weight = float(weight)
bmi = height / (weight * weight)

This code will convert height and weight to floats before calculating the BMI. If the conversion isn't possible (for example, if height or weight contains non-numeric characters), this code will raise a ValueError.

This problem has been solved

Similar Questions

# 1st input: enter height in meters e.g: 1.65height = input()# 2nd input: enter weight in kilograms e.g: 72weight = input()# 🚨 Don't change the code above 👆# Write your code below this line 👇height = float(height)weight = float(weight)weight = weight ** 2 bmi = int(height / (weight))print(bmi)

Create a function of name get_bmi() that receive the weight in kilograms and height in centimeter of a person and return his or her Body Mass index (BMI). The function should convert the height to meters before calculating the BMI.Height in meter = height in centimeter / 100BMI = weight in kilogram / (height in meter * height in meter)

Using %mprun: Hero BMIYou'd like to calculate the body mass index (BMI) for a selected sample of heroes. BMI can be calculated using the below formula:A random sample of 25,000 superheroes has been loaded into your session as an array called sample_indices. This sample is a list of indices that corresponds to each superhero's index selected from the heroes list.A function named calc_bmi_lists has also been created and saved to a file titled bmi_lists.py. For convenience, it is displayed below:def calc_bmi_lists(sample_indices, hts, wts): # Gather sample heights and weights as lists s_hts = [hts[i] for i in sample_indices] s_wts = [wts[i] for i in sample_indices] # Convert heights from cm to m and square with list comprehension s_hts_m_sqr = [(ht / 100) ** 2 for ht in s_hts] # Calculate BMIs as a list with list comprehension bmis = [s_wts[i] / s_hts_m_sqr[i] for i in range(len(sample_indices))] return bmisNotice that this function performs all necessary calculations using list comprehension (hence the name calc_bmi_lists()). Dig deeper into this function and analyze the memory footprint for performing your calculations using lists:Load the memory_profiler package into your IPython session.Import calc_bmi_lists from bmi_lists.Once you've completed the above steps, use %mprun to profile the calc_bmi_lists() function acting on your superheroes data. The hts array and wts array have already been loaded into your session.After you've finished coding, answer the following question:How much memory do the list comprehension lines of code consume in the calc_bmi_lists() function? (i.e., what is the total sum of the Increment column for these four lines of code?)

John is a fitness trainer and needs to calculate the Body Mass Index (BMI) for his clients to assess their health status. Write a program for him that takes the weight in kilograms and height in meters of a client as input, calculates their BMI, and determines if they fall within the healthy range.Note: The healthy range of BMI is 18.5 to 24.9 (both inclusive).Input format :The input consists of two double values: the weight in kilograms and the height in meters.Output format :The first line of output prints "BMI: X" where X is a double value, rounded off to two decimal places.The second line prints one of the following:If the BMI is within the valid range, print "Healthy Range".Otherwise, print "Not in Healthy Range".Refer to the sample output for formatting specificationsCode constraints :10.0 ≤ weight ≤ 300.00.00 ≤ height ≤ 3.00Sample test cases :Input 1 :65.81.75Output 1 :BMI: 21.49Healthy RangeInput 2 :124.31.87Output 2 :BMI: 35.55Not in Healthy Range

Single File Programming QuestionProblem StatementBalaji wants your help to design a fitness calculator. The simple measure of body fitness is the BMI or Body Mass Index. It depends only on the height L and weight W of a person. It is defined as BMI = [weight / height2] where weight is taken in kilograms and length in meters. Four general grades are proposed:Underweight[U] - when BMI < 18.5Normal weight[N] - 18.5 <= BMI < 25.0Heavyweight [H] - 25.0 <= BMI < 30.0Overweight [O] - above or equal to 30.0Write a program that takes in the Weight (in Kg) and Length (in meters) of an individual and displays the grade as U, N, H, O.Note: Store all the variables in register memory.Input format :The first line of input consists of an integer, representing the weight.The second line consists of a double value, representing the height in meters.Output format :The output displays the grade based on the given conditions.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:60 ≤ weight ≤ 2001.0 ≤ height ≤ 5.0Sample test cases :Input 1 :1303.5Output 1 :UInput 2 :2002.7Output 2 :HInput 3 :902.1Output 3 :NInput 4 :741.3Output 4 :O

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.