Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python while loop and recursion

# bmi calculation function
def bmi_calc(weight, height):
    bmi = round(weight / (height * height))

    if bmi < 18.5:
        print(f"Your BMI is ({bmi}), you are underweight.")
    elif bmi < 25:
        print(f"Your BMI is ({bmi}), you have a normal weight.")
    elif bmi < 30:
        print(f"Your BMI is ({bmi}), you are slightly overweight.")
    elif bmi < 35:
        print(f"Your BMI is ({bmi}), you are obese.")
    else:
        print(f"Your BMI is ({bmi}), you are clinically obese.")
        
    return bmi

# flag
continue_bmi_test = True

# if the bmi test is True loop
while continue_bmi_test == True:
    height = float(input("enter your height in m: "))
    weight = float(input("enter your weight in kg: "))
    
    result = bmi_calc(weight, height)
    print(result)
    
    continue_check = input("Continue? 'y' or 'n'")

    if continue_check == "y":
        result
    elif continue_check == "n":
        print("Goodbye!")
        continue_bmi_test = False
    else:
        print("Invalid input, goodbye!")
        continue_check = False
        
Comment

PREVIOUS NEXT
Code Example
Python :: endgame 
Python :: gnuplot sum over a column 
Python :: python api with live ercot real time prices 
Python :: how to make a time limit using renpy 
Python :: flask decorator causes views to be named the same thing 
Python :: Convert the below Series to pandas datetime : DoB = pd.Series(["07Sep59","01Jan55","15Dec47","11Jul42"]) 
Python :: file = Root() path = file.fileDialog() print("PATH = ", path) 
Python :: create bbox R sp 
Python :: ftplib tqdm 
Python :: how to use list compression with conditional formatting 
Python :: notebook python static website generator 
Shell :: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation 
Shell :: bitnami restart apache 
Shell :: npm install upgrade react version react-scripts 
Shell :: how to uninstall react native cli globally 
Shell :: ubuntu extract rar 
Shell :: check gnome version ubuntu terminal 
Shell :: git clean cache 
Shell :: ubuntu settings not opening 20.04 
Shell :: remove remote origin github 
Shell :: install fira code vscode ubuntu 
Shell :: mac terminal find process by port 
Shell :: linux sort folders by size 
Shell :: download filezilla in ubuntu 
Shell :: check if nginx is running 
Shell :: remove xampp from ubuntu 
Shell :: remove stopped containers 
Shell :: ps1 file not digitally signed 
Shell :: ubuntu install imagemagick 
Shell :: mac restart mysql server 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =