5. CONDITIONAL STATEMENTS AND NESTED CONDITIONS

These free B.Pharm notes on python conditional statements if elif else cover chapter 5 of Basics of Python Programming for Pharmaceutical Sciences (BP101T), a first-semester subject. Read the key points below, then study the complete chapter PDF. You can browse every chapter in the Basics of Python Programming for Pharmaceutical Sciences category.

Read the following document for full information

Overview of python conditional statements if elif else

These notes introduce control structures and explain how conditional statements let a program make decisions. They cover the if statement, the if-else statement and the if-elif-else statement with syntax and examples, then explain nested conditions and their order of evaluation, and finish with pharmacy programs for drug allergy checks, fever detection, blood sugar classification and drug dispensing safety.

Key points on python conditional statements if elif else

  • Control structures govern how a program runs its instructions, allowing it to make decisions and repeat actions instead of running every line in a fixed sequence.
  • An if statement tests a condition, and its indented block runs only when the condition is True; when it is False the block is skipped.
  • The if-else statement gives two alternative paths, running the if block when the condition is True and the else block when it is False.
  • The if-elif-else statement chooses among more than two possibilities, and the else part runs only when none of the earlier conditions is true.
  • A nested condition is an if inside another if, where the inner condition is checked only after the outer condition has been found True.

Relevance to pharmacy practice

Clinical decisions such as reducing a dose for senior patients, detecting fever or classifying blood sugar readings follow clear if-then rules that Python can apply quickly and consistently. Nested checks, like confirming a valid prescription and then checking for allergy, model safe drug dispensing in pharmacy software.

Every chapter in this subject builds on the one before it, so do not skip topics that look simple. Definitions, principles, procedures and examples are the parts that examiners return to most often, and a clear understanding here will also make later subjects easier to follow in the coming semesters.

Frequently asked questions on python conditional statements if elif else

What is the difference between if-else and if-elif-else in Python?

The if-else statement chooses between two paths only. The if-elif-else statement is used when a program must choose among more than two possibilities, with each elif checking another condition in turn.

What is a nested if statement?

A nested if statement places one if, if-else or if-elif-else statement inside another if statement. It is useful when one condition can only be checked after another has been confirmed true.

How can Python check a drug allergy?

The notes use an if statement that converts the entered allergy to lowercase with allergy.lower() and compares it with “penicillin”, printing a warning to avoid penicillin-based drugs.

Quick revision checklist

Use this self-test after reading the chapter on python conditional statements if elif else. If you can do all of the following without looking at your notes, you are ready for the exam.

  • I can explain: what control structures do in a program
  • I can explain: the if statement and its syntax
  • I can explain: if-else and if-elif-else statements
  • I can explain: how nested conditions are evaluated
  • I can explain: pharmacy examples like fever and blood sugar

Study and exam tips

Start by reading the chapter once for the overall idea, then revise python conditional statements if elif else using headings, definitions, principles, reactions and examples. Short-answer questions in the university exam usually ask for definitions, principles, procedures, reactions and uses, so write these in your own words and practise the equations, tables and flow charts that the chapter has.

For wider reading, standard books and open resources such as the NCBI Bookshelf help you confirm terms and see more examples. Revise python conditional statements if elif else again a day later and again a week later, because spaced revision improves long-term memory.

This page is part of the Basics of Python Programming for Pharmaceutical Sciences series for first-semester B.Pharm students on B.Pharm Guru, where every chapter has a short summary and a full PDF. Bookmark this page and share it with classmates who are preparing for the same exam.

Related notes: 7. BREAK, CONTINUE, AND PASS STATEMENTS, 8. DEFINING AND CALLING FUNCTIONS, PASSING ARGUMENTS AND RETURNING VALUES..

Next: 6. LOOPS – FOR LOOP AND WHILE LOOP. Back to the Basics of Python Programming for Pharmaceutical Sciences category.