Control Structures and Functions-BPPS Notes

Class Notes · Free · 35 pages · Basics of Python Programming for Pharmaceutical Sciences · Topic: Control Structures and Functions

Preview

Control Structures and Functions-BPPS Notes — page 1Control Structures and Functions-BPPS Notes — page 2

Summary

These notes cover all of Unit II: Control Structures and Functions, written for first-year B.Pharm students and following on from Unit I. They explain conditional statements (if, if–else, if–elif–else and nested if) with flowcharts and indentation rules. Next they cover for and while loops, range(), and the break and continue statements. Then they explain functions: defining and calling them, parameters and arguments, and return values. The unit ends with modular programs, with complete worked programs for BMI calculation and dose calculation. Every example uses pharmacy situations, such as checking whether a dose is above the maximum, and can be run in the free Pharmakaksha Python Lab. The notes have flowcharts, code panels with output, 30 MCQs with an answer key, 20 short-answer questions and 4 long-answer questions with answer plans.

Key points

  • Conditional statements: if, if–else, if–elif–else and nested if with syntax, flowcharts and indentation rules, using pharmacy decisions such as "is this dose above the maximum?"
  • Loops: for and while loops, range(), when to use each (known count → for, repeat until a condition → while), with examples like checking tablets one by one.
  • break and continue: How to stop a loop early or skip one round, with simple worked examples and common mistakes such as infinite loops.
  • Functions made simple: Defining and calling a function, parameters vs arguments ("the parameter is the place-holder, the argument is the actual value"), return values and why functions are reused.
  • Modular programs: Splitting a program into small functions and modules, with complete worked programs for BMI calculation and classification and paediatric dose calculation.

Log in or create a free account to read the full note. More in Notes and the Study Library.