Knowee
Questions
Features
Study Tools

Define a function BMRCalculator(), which would complete the above-mentioned processes from section 1.1 to 1.7:Within the function, print the message "Would you like to try again? [Y/N]".If the user types 'Y', BMRCalculator() will repeat the process.If the user types 'N', the program will stop. When the program stops, it returns the python dictionary with the whole data, write the data in a json file 'data.json'.The json file should include key and value pairs (id, attributes) where each item reppresents a person. The value itself is a dictionary with {name, gender, age, height, mass, weight, bmr}.HintUse similar codes in section 1.7 to create the file, but with the following codes:value_tup = (name, gender, age, height, weight, bmr)dic_item = dict(zip(key, value_tup))

Question

Define a function BMRCalculator(), which would complete the above-mentioned processes from section 1.1 to 1.7:Within the function, print the message "Would you like to try again? [Y/N]".If the user types 'Y', BMRCalculator() will repeat the process.If the user types 'N', the program will stop. When the program stops, it returns the python dictionary with the whole data, write the data in a json file 'data.json'.The json file should include key and value pairs (id, attributes) where each item reppresents a person. The value itself is a dictionary with {name, gender, age, height, mass, weight, bmr}.HintUse similar codes in section 1.7 to create the file, but with the following codes:value_tup = (name, gender, age, height, weight, bmr)dic_item = dict(zip(key, value_tup))

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

Solution

The text you provided seems to be a task description for creating a Basal Metabolic Rate (BMR) calculator function in Python. Here's how you can do it:

import json

def BMRCalculator():
    data = {}
    id = 1
    while True:
        name = input("Enter your name: ")
        gender = input("Enter your gender: ")
        age = int(input("Enter your age: "))
        height = float(input("Enter your height in cm: "))
        weight = float(input("Enter your weight in kg: "))
        
        if gender.lower() == 'male':
            bmr = 66 + (13.75 * weight) + (5.003 * height) - (6.755 * age)
        else:
            bmr = 655 + (9.563 * weight) + (1.850 * height) - (4.676 * age)
        
        print(f"Your BMR is: {bmr}")
        
        value_tup = (name, gender, age, height, weight, bmr)
        key = ['name', 'gender', 'age', 'height', 'weight', 'bmr']
        dic_item = dict(zip(key, value_tup))
        
        data[id] = dic_item
        id += 1
        
        repeat = input("Would you like to try again? [Y/N] ")
        if repeat.lower() != 'y':
            break
    
    with open('data.json', 'w') as json_file:
        json.dump(data, json_file)
    
    return data

This function will ask for user input, calculate the BMR based on the input, and store the data in a dictionary. If the user wants to try again, it will repeat the process. If not, it will write the data to a JSON file and return the data.

This problem has been solved

Similar Questions

How to program in Python?

For the Python program below, will there be any output, and will the program terminate?while True:    while 1 > 0:        break    print("Got it!")    breakQuestion 9Select one:a.Yes and nob.No and noc.Yes and yesd.No and yese.Run-time error

8.Question 8You wrote the following code:if attempts >= 5: print("locked")else: print("try again")If the value in the attempts variable is 3, what will Python do?1 pointOutput the message "try again"First output the message "locked" and then output the message "try again"First output the message "try again" and then output the message "locked"Output the message "locked"

Outline the process of input, processing, and output in Python programs. Describe a real-worldscenario where this process is crucial, such as data entry and processing in a retail system. (5 Marks)

import randomimport jsondef intermediate_step_multi_run_process(request):    def generate():        counter = 0        while counter < 2:            time.sleep(0.3)            random_no_list = []             for i in range(1000000000):                random_no = random.random() ** 2                random_no_list.append(random_no)            random_no_list = json.dumps(random_no_list)            yield "data:" + random_no_list + "\n\n"            counter += 1    return StreamingHttpResponse(generate(), content_type="text/event-stream")           The above stated is an async function triggered by a websocket in a web application to render the list of 100 million squared random numbers. What is the possible error that this piece of code could result in a wsgi application and why?

1/1

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.