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))Call the function you defined and input at least 5 data items (people)Example output for file data.json:{ "0": { "name": "Mark", "gender": 1, "age": 29, "height": 180, "weight": 156.0, "bmr": 1765.0 }, "1": { "name": "Jenny", "gender": 2, "age": 21, "height": 150, "weight": 90.0, "bmr": 1121.5 }, "2": { "name": "Xia", "gender": 2, "age": 29, "height": 170, "weight": 110.0, "bmr": 1306.5 }, "3": { "name": "Brian", "gender": 1, "age": 20, "height": 169, "weight": 132.0, "bmr": 1621.25 }, "4": { "name": "Cleo", "gender": 1, "age": 20, "height": 166, "weight": 110.0, "bmr": 1492.5 }}

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))Call the function you defined and input at least 5 data items (people)Example output for file data.json:{ "0": { "name": "Mark", "gender": 1, "age": 29, "height": 180, "weight": 156.0, "bmr": 1765.0 }, "1": { "name": "Jenny", "gender": 2, "age": 21, "height": 150, "weight": 90.0, "bmr": 1121.5 }, "2": { "name": "Xia", "gender": 2, "age": 29, "height": 170, "weight": 110.0, "bmr": 1306.5 }, "3": { "name": "Brian", "gender": 1, "age": 20, "height": 169, "weight": 132.0, "bmr": 1621.25 }, "4": { "name": "Cleo", "gender": 1, "age": 20, "height": 166, "weight": 110.0, "bmr": 1492.5 }}

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

Solution

It seems like you're asking for a Python function that calculates the Basal Metabolic Rate (BMR) for multiple users and stores the data in a JSON file. Here's a simple implementation of such a function:

import json

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

    return data

You can call this function and input data for as many people as you want. The function will keep asking for data until you choose not to continue. The data will be stored in a dictionary and written to a file named 'data.json'.

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.