DEV Community

David Bosah
David Bosah

Posted on

Beginners Python Decision Making: Understanding If-else statements effectively.

If-Else statements and its significance:

"If-else" statements are a type of conditional statements in programming which allows specific logic or conditions to be given to different blocks of code. It's literally creating a bias or condition to a code block. The benefits range from making decisions to controlling possibilities.

Practical example:

Lets say we want to write a code about weight information in such a manner that if the user is above 130kg He/She is overweight, see how we are going to write it.


Weight = int(input("enter your weight in kg here"))

if weight >= 130:
   print("You are overweight ")

else:
   print("You are good to go")

Enter fullscreen mode Exit fullscreen mode

Principles you must apply:

  1. Ensure to use small letters for your functions.

  2. Keep it simple, avoid ambiguity.

  3. Use ":" after 'else' to avoid error.

  4. Use integer function "int" to indicate that the expected input value is a number not a letter.

Top comments (0)