Wednesday, April 21, 2021

How to create BMI Calculator in Python [Source Code]


If you are a beginner and getting started with python programming it is recommended to write small python codes to understand the basics, instead of viewing videos for solutions.


Here, we try to accomplish a simple task by writing a Body Mass Index Calculator in Python Script. For this purpose we need to understand what a Body Mass Index Calculator is. If you google what is Body Mass Index you are gonna get the following definition.


“an approximate measure of whether someone is over- or underweight, calculated by dividing their weight in kilograms by the square of their height in metres.”

 

 

Thats simple you calculate your weight with respect to your height to determine whether you are overweight or not. Now that we have understood what body mass index (BMI) is, we need to know the formula of it to implement it in the python programming language. The formula is following

 

BMI = Weight / Height²

 

 

Keep in mind that weight is in Kilograms and Height is in Meters. Users must know this before entering values.

 

Next thing we should do is to tell the user their Body Mass Index with attributes (overweight, underweight or normal) again, to do that we should know the range of value of  attributes. These are the range of Body Mass Index (BMI)

 

BMI weight ranges

  • Less than 18.5 = Underweight

  • Between 18.5 - 24.9 = Healthy Weight

  • Between 25 - 29.9 = Overweight

  • Over 30 = Obese

  • Over 35 = Critically Obese

 

INFORMATION SOURCE

 

Now we create a flow chart for our python script it is not necessary but very useful

 

BMI Calculator In Python Programming Language

 

 

 

To begin our python script we start by a welcome message which tells a user about functionality of our program.

 

print("\n\n\t\tBMI Calculator Using Functions\n\n")

 

Next, ask user to input values. In python if we want a user to input a value we simply use the “input()” function which returns text value and to perform mathematical division we need the user input value to be an integer so we add “int()” function before it. Remember that in python language the “input()” function returns a value so we will need a variable to store it. As shown in flowchart we create a variable named “Weight” and same flow goes for “Height”

 

weight = int(input("Enter your weight in KG: "))

height = float(input("Enter your height in Meters: "))

 

 

That’s it. In python programming language if we need to make decisions “we use if else,” but in this python script we will use “if elif and else” because we have multiple values to check another main thing which should be followed strictly is that we always start from lowest value by doing this we avoid doing excessive if’s and elif’s. Simply write

 

 if BMI < 18.5:

        print(f"Your BMI is {BMI}, you are underweight")

    elif BMI < 25:

        print(f"Your BMI is {BMI}, you have normal weight")

    elif BMI < 30:

        print(f"Your BMI is {BMI}, you are overweight")

    elif BMI < 35:

        print(f"Your BMI is {BMI}, your are obese")

    else:

        print(f"Your BMI is {BMI}, you are clinically obese")

 

 

Our python program is finished here but to simplify we will add if’s into a function

 

def BMI_Calculator(user_weight, user_height):

    BMI = round(weight/(height*height),2)

    if BMI < 18.5:

        print(f"Your BMI is {BMI}, you are underweight")

    elif BMI < 25:

        print(f"Your BMI is {BMI}, you have normal weight")

    elif BMI < 30:

        print(f"Your BMI is {BMI}, you are overweight")

    elif BMI < 35:

        print(f"Your BMI is {BMI}, your are obese")

    else:

        print(f"Your BMI is {BMI}, you are clinically obese")    

 

Feel free to copy the code and share your feedback.

Program Source Code 👇 | Select and Press CTRL + C to copy the code

#BMI Calculator 2.0
def BMI_Calculator(user_weightuser_height):
    BMI = round(weight/(height*height),2)
    if BMI < 18.5:
        print(f"Your BMI is {BMI}, you are underweight")
    elif BMI < 25:
        print(f"Your BMI is {BMI}, you have normal weight")
    elif BMI < 30:
        print(f"Your BMI is {BMI}, you are overweight")
    elif BMI < 35:
        print(f"Your BMI is {BMI}, your are obese")
    else:
        print(f"Your BMI is {BMI}, you are clinically obese")    

print("\n\n\t\tBMI Calculator Using Functions\n\n")

weight = int(input("Enter your weight in KG: "))
height = float(input("Enter your height in Meters: "))


BMI_Calculator(user_weight=weight, user_height=height)



Program Output « 👇

                BMI Calculator Using Functions

  

Enter your weight in KG: 45

Enter your height in Meters: 1.1

Your BMI is 37.19, you are clinically obese


BMI calculator output in python programming language




Thursday, December 24, 2020

Assembly Language Program To Find Even And Odd Numbers In 8086


This program takes user input as an array and then determines the number of even numbers and prints them. This program is written using 8086 assembly language using emu8086 software.




TITLE PUCHTAA 
.MODEL SMALL 
.STACK 100H 
.DATA 
    MSG1 DB 0AH, 0DH, "THIS PROGRAM ACCEPTS SIZE OF ARRAY AND ELEMENTS THEN PRINTS EVEN NUMBERS$" 
    MSG DB 0AH, 0DH, "ENTER A LENGHT OF ARRAY: $" 
    ARRAY DB 0AH, 0DH, "ENTER ELEMENTS OF ARRAY$" 
    EVEN DB 0AH, 0DH, "TOTAL EVEN NUMBERS ARE $" 
    CONTINUE DB 0AH, 0DH, "CONTINUE? [Y/N] $" 
    NOEVEN DB 0AH, 0DH, "NO EVEN NUMBERS IN ARRAY!!$" 
 
 
 
 
.CODE 
    MAIN: 
    MOV AX, @DATA 
    MOV DS, AX 
     
    LEA DX, MSG1 
    MOV AH, 09H 
    INT 21H 
    CONT:    
    LEA DX, MSG 
    MOV AH, 09H 
    INT 21H 
     
    MOV AH, 01H 
    INT 21H 
     
    SUB AL, 30H 
    MOV CL, AL 
     
    LEA DX, ARRAY 
    MOV AH, 09H 
    INT 21H 
     
    MOV CH, 00H 
     
    AGAIN: 
    MOV DL, ' ' 
    MOV AH, 02H 
    INT 21H 
     
    MOV AH, 01H 
    INT 21H 
     
    SUB AL, 30H 
    MOV AH, 00H 
    MOV BL, 02H 
    AAD 
    DIV BL 
    CMP AH, 00H 
    JE INCREASE 
    RETURN: 
     
    DEC CL 
    CMP CL, 00H 
    JG AGAIN 
     
    CMP CH, 00H 
    JE NOEVENS 
     
    LEA DX, EVEN 
    MOV AH, 09H 
    INT 21H 
     
    JMP NUM 
     
 NOEVENS: 
    LEA DX, NOEVEN 
    MOV AH, 09H 
    INT 21H 
    JMP QUEST 
     
    
 NUM: 
     
    MOV DL, ' ' 
    MOV AH, 02H 
    INT 21H 
    
    POP AX 
    MOV DL, AH 
    ADD DL, 30H 
    MOV AH, 02H 
    INT 21H 
    DEC CH 
    CMP CH, 00H 
    JNE NUM 
 QUEST:    
    LEA DX, CONTINUE 
    MOV AH, 09H 
    INT 21H 
     
    MOV AH, 01H 
    INT 21H 
    OR AL, 20H 
    CMP AL, 'y' 
    JE CONT 
     
    JMP EXIT 
     
     
     
     
     
     
    INCREASE: 
    MOV AH, AL 
    ADD AH, AL 
    PUSH AX 
    INC CH 
    JMP RETURN 
     
    EXIT: 
    MOV AH, 4CH 
    INT 21H 
    END MAIN 

Finding Even Numbers In 8086 Assembly


Tuesday, May 19, 2020

[Solved] Creating Nested Loops in ascending order in Assembly Language

The following code demonstrates nested loops in ascending order example in 8086 Assembly Language Programming. Related program can be found here




TITLE PUCHTAA  
.MODEL SMALL  
.STACK 100H  
.DATA  
  
  
.CODE  
    MAIN:  
        MOV AX, @DATA  
        MOV DS, AX  
          
        MOV CL, 31H  
    LOOP1:  
        MOV DL, CL  
    LOOP2:  
        MOV AH, 02H  
        INT 21H  
          
        INC DL  
        CMP DL, 37H  
        JNG LOOP2  
          
        MOV DL, 0AH  
        MOV AH, 02H  
        INT 21H  
          
          
        MOV DL, 0DH  
        MOV AH, 02H  
        INT 21H  
          
          
        INC CL  
        CMP CL, 37H  
        JNG LOOP1  
          
           
          
        MOV AH, 04CH  
        INT 21H  
    END MAIN 
 
OUTPUT OF THE PROGRAM 
 
NESTED LOOPS IN ASCENDING ORDER IN ASSEMBLY LANGUAGE PROGRAMMING
 

Saturday, May 16, 2020

How to Print Sum of Series in Assembly Language


This Program Prints the sum of a series, of a number which is input by the user.



TITLE PUCHTAA 
.MODEL SMALL 
.STACK 100H 
.DATA 
    INTRO DB 0AH, 0DH, 07H, 09H, "THIS PROGRAM PRINTS THE SUM OF SERIES$" 
    MSG DB 0AH, 0DH, "ENTER A NUMBER: $" 
    NEWLINE DB 0AH, 0DH, "$" 
    DOAGAIN DB 0AH, 0DH, "DO AGAIN? Y FOR YES ELSE FOR NO: $" 
.CODE 
 
    MAIN: 
        MOV AX, @DATA 
        MOV DS, AX 
 
        LEA DX, INTRO 
        MOV AH, 09H 
        INT 21H 
 
         
    NUMBER:     
        LEA DX, MSG 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
         
        SUB AL, 30H 
        CMP AL, 09H 
        JG NUMBER 
         
         
        MOV BL, AL 
        MOV BH, AL 
        PUSH BX 
        CMP AL, 00H 
        JE RESULT 
   AGAIN: 
         
         
        DEC BL 
        ADD BH, BL 
        CMP BL, 00H 
        JG AGAIN 
         
        MOV AH, 00H 
        MOV AL, BH 
        MOV BL, 0AH 
        DIV BL 
        MOV BX, AX 
        POP CX 
  RESULT:       
        LEA DX, NEWLINE 
        MOV AH, 09H 
        INT 21H 
        MOV CH, 00H 
         
  DISPLAY: 
        MOV DL,CH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, '+' 
        MOV AH, 02H 
        INT 21H 
         
        INC CH 
        CMP CH, CL 
        JLE DISPLAY  
         
         
        MOV DL, 08H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, '=' 
        MOV AH, 02H 
        INT 21H 
         
         
         
        MOV DL,BL 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H       
         
        MOV DL, BH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        LEA DX, DOAGAIN 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
        OR AL, 20H 
        CMP AL, 'y' 
        JE NUMBER 
         
         
        MOV AH, 4CH 
        INT 21H 
    END MAIN 

OUTPUT of the program

Sum of Series Programming in Assembly Language
  • assembly language program for sum of series
  • sum of series in assembly language
  • series addition azevedotechcrunch

Click to Download Code

Download

Thursday, March 26, 2020

How To Find Length Of String In 8086 Assembly Language [Click to Download Code]


This program prints the length of user input string in 8085/8086 microprocessor assembly language programming


TITLE PUCHTAA 
.MODEL SMALL 
.STACK 100H 
.DATA 
 
    MSG1 DB 0AH, 0DH, "ENTER A STRING--> $" 
    MSG2 DB 0AH, 0DH, "NUMBER OF CHARACTERS ENTERED--> $" 
    INMSG DB 25 DUP('0') 
     
.CODE 
    MAIN: 
        MOV AX, @DATA 
        MOV DS, AX 
;----------------DISPLAY THE MESSAGE------------------ 
   AGAIN:      
        LEA DX, MSG1 
        MOV AH, 09H 
        INT 21H 
;----------------------------------------------------- 
         
;-----------TAKE STRING INPUT------------------------         
        LEA SI, INMSG 
        MOV DX, SI 
        MOV AH, 0AH 
        INT 21H 
         
        MOV SI, 02H 
        CMP INMSG+SI, 0DH 
        JE EXIT 
;---------------------------------------------------         
        LEA DX, MSG2 
        MOV AH, 09H 
        INT 21H 
;----------SET SOURCE INDEX(SI) VALUE TO 1---------- 
;----------BECAUSE FIRST INDEX TELLS NUMBER OF BYTES READ--------         
        MOV SI,01H 
         
        MOV AL, INMSG+SI 
        MOV AH, 00H 
        MOV BL, 0AH ; 
        AAD         ; 
        DIV BL      ;BREAKING THE VALUE IF IT EXCEEDS 10 
;--------------------------------------------------------         
        MOV DX, AX 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, DH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
        JMP AGAIN 
   EXIT:      
         
        MOV AH, 04CH 
        INT 21H 
    END MAIN


TAGS:
  • find length of string in assembly language 8086
  • 8086 program to find length of a string
  • length of string in assembly language
  • string length assembly
  • assembly get length of string
  • length of string assembly
  • assembly length of string
  • assembly string length
  • how to find length of string in assembly language
  • get length of string assembly
  • how to get the length of a string in assembly
  • how to find the length of a string in assembly
  • string length in assembly language
 
How to Count Lenght of a given string in assembly language- OUTPUT

Complete Video Tutorials