calculator python code code example
Example 1: python bmi calculator code
print("Welcome to BMI calculator, by Abthahi Tazrian.")
Offer_Conversions = input("Would you like to convert your imperial units to metric? (yes / no): ")
if Offer_Conversions == "yes":
Imperial_Weight = input("What is your weight in pounds?: ")
Imperial_Height = input("What is your height in feet (decimals)?: ")
Imperial_Weight = float(Imperial_Weight)
Imperial_Height = float(Imperial_Height)
Metric_Converted_Weight = Imperial_Weight * 2.205
Metric_Converted_Height = Imperial_Height * 30.48
Metric_Converted_Weight = str(Metric_Converted_Weight)
Metric_Converted_Height = str(Metric_Converted_Height)
print("Your metric weight is " + Metric_Converted_Weight + " kg, please note this for the next stage.")
print("Your metric height is " + Metric_Converted_Height + " cm, please note this for the next stage.")
print("--")
elif Offer_Conversions == "no":
print("--")
Age = input("Put in your age: ")
Weight = input("Put in your weight in KG: ")
Height = input("Put in your height in CM: ")
Weight = float(Weight)
Height = float(Height)
Height_Squared = Height * Height
BMI_Formula_Assisted = Weight / Height_Squared
BMI_Formula_Completed = BMI_Formula_Assisted * 10000
BMI_Formula_Completed = str(BMI_Formula_Completed)
print("You have a BMI score of " + BMI_Formula_Completed + ".")
BMI_Formula_Completed = float(BMI_Formula_Completed)
if BMI_Formula_Completed <= 18.5:
print("You are underweight, consider gaining weight to bring your BMI to between 20 and 25.")
elif BMI_Formula_Completed <= 25:
print("You are perfectly healthy, with a BMI within a healthy range of between 20 and 25.")
elif BMI_Formula_Completed <= 30:
print("You are overweight, speak to a doctor about setting yourself a new target BMI between 20 and 25.")
elif BMI_Formula_Completed >= 30.1:
print("You are obese, you need to lower your BMI to between 20 and 25 or else you may be at risks.")
Example 2: python calculator
def calculate():
print('Please choose your operator adding(+) subtracting(-) multiplying(*) didviding(/) for power(**) for module(%)')
number_1 = int(input("Enter your first digit: "))
operation = input("Enter your operator: ")
number_2 = int(input("Enter your first digit: "))
if operation == '+':
print('{} + {} = '.format(number_1, number_2))
print(number_1 + number_2)
print("You were adding.\n")
print("How do I know that I'm a smart progammer ;)\n")
elif operation == '-':
print('{} - {} = '.format(number_1, number_2))
print(number_1 - number_2)
print("You were subtracting.\n")
print("How do I know that I'm a smart progammer ;)\n")
elif operation == '*':
print('{} * {} = '.format(number_1, number_2))
print(number_1 * number_2)
print("You were mulitplaying.")
print("How do I know that I'm a smart progammer ;)\n")
elif operation == '/':
print('{} / {} = '.format(number_1, number_2))
print(number_1 / number_2)
print("You were dividing.\n")
print("How do I know that I'm a smart progammer ;)\n")
elif operation == '**':
print('{} ** {} = '.format(number_1, number_2))
print(number_1 ** number_2)
print("You were using for power.\n")
print("How do I know that I'm a smart progammer ;)\n")
elif operation == '%':
print('{} % {} = '.format(number_1, number_2))
print(number_1 % number_2)
print("You were using module.\n")
print("How do I know that I'm a smart progammer ;)\n")
else:
print("Your number you have typed is invalid, please restart your program!")
again()
def again():
cal_again = input("Do you want to calculate again? Y = yes or N = no: ")
if cal_again.upper() == 'Y':
calculate()
elif cal_again.upper() == 'N':
print('Leave kid ;-;')
else:
again()
def welcome():
print("Welcome to my calculator made by Pepa pig lol made in python :D")
welcome()
calculate()