PHARMACY PRACTICE-III (PHARM
519)
CHAPTER VIII – FUNDAMENTALS OF PROGRAMMING
BY:
HUZAIFA BIN AZHAR
INTRODUCTION TO PROGRAMMING
Programming is the process of giving a computer instructions, or
"code," to perform specific tasks, enabling it to solve problems
and execute operations.
Programmers use specialized languages (like Python, JavaScript,
C++, etc.) to write these instructions, which are then translated
by the computer into a format it can execute.
Programming is essential for creating software, applications,
websites, and many other technologies that we use daily, from
mobile apps to online banking.
PROGRAMMING LANGUAGES
• Examples: Python, C++, Java, JavaScript
• High-level vs low-level
• Compiled vs interpreted languages
PROGRAMMING LANGUAGES
• High-level languages are designed for human readability and ease of use,
while low-level languages are closer to machine code, offering fine-grained
control and efficiency. Python, Java, C++, JavaScript.
Human-Friendly:
• They use syntax and concepts that are easier for humans to understand and
write.
Abstraction:
• They abstract away low-level details of the computer's hardware, allowing
programmers to focus on the problem at hand.
Portability:
• Code written in high-level languages is often more portable, meaning it can
run on different platforms with minimal changes.
PROGRAMMING LANGUAGES
Low-Level Languages:
• Machine-Oriented: They are designed to be directly understood
by the computer's hardware.
• Fine-Grained Control: They provide direct access to hardware
resources, allowing for fine-grained control over the computer's
operation.
• Examples: Assembly language and machine code are examples
of low-level languages.
• Efficiency: Low-level languages can produce more efficient code,
as they allow for more direct manipulation of the hardware.
• Platform-Specific: Code written in low-level languages is often
highly platform-specific, meaning it may not run on different
hardware architectures.
PROGRAMMING LANGUAGES
In programming, a compiled language requires a separate
compilation step where the code is translated into machine code
before execution, while an interpreted language executes
instructions directly, often line by line, without prior compilation.
Compiled Languages:
Compilation: The source code is translated into machine code (or
an intermediate representation like bytecode) by a compiler.
Execution: The compiled code is then executed directly by the
processor.
Examples: C, C++, Java, Go
Advantages: Generally faster execution speed, better optimization,
and more efficient memory usage.
Disadvantages: Compilation time, platform dependency (compiled
PROGRAMMING LANGUAGES
Interpreted Languages:
Interpretation: The source code is read and executed directly by
an interpreter, which translates and executes instructions line by
line.
Execution: The interpreter handles the translation and execution
of the code at runtime.
Examples: Python, JavaScript, Ruby, PHP
Advantages: Faster development and testing (no compilation
required), platform independence (interpreters can run on
different architectures).
Disadvantages: Slower execution speed compared to compiled
languages, potential for runtime errors.
VARIABLES AND CONSTANTS
What is a Variable?
• A variable is a name given to a memory location where data
is stored.
• Think of it like a labeled box where you keep a value that might
change.
VARIABLES AND CONSTANTS
A constant is like a variable, but its value cannot be changed
after it is set.
It’s used when you want to protect important values from being
modified.
DATA TYPES
Integer (int)
Stores whole numbers (no decimals).
Examples: -5, 0, 42, 2025
DATA TYPES
Floating Point (float / double)
Stores decimal numbers or fractions
Examples: 3.14, -0.99, 2.0
DATA TYPES
String (str)
sequence of characters (letters, numbers, symbols).
Used for names, messages, text input/output.
DATA TYPES
Boolean (bool)
Only two values: True or False
Used for decision making or conditions
DATA TYPES
Character (char) (C++ specific)
Stores a single character
SYNTAX
• Rules a programming language follows.
• Example in Python:
• print("Hello, Pharmacy World!")
CONDITIONALS (IF-ELSE)
• Used for decision-making.
• Example:
if dosage_mg > 400:
print("High dosage!")
else:
print("Safe dosage.")
LOOPS
• Used to repeat actions.
• Example (math loop):
for i in range(1, 6):
print(i * i) # Prints squares of 1 to 5
FUNCTIONS
• Reusable blocks of code.
• Example:
def greet_patient(name):
print("Hello, " + name)
greet_patient("Ali")
LISTS AND DICTIONARIES
• List: ordered items, Dictionary: key-value
pairs.
• List:
meds = ["Paracetamol", "Ibuprofen"]
• Dictionary:
drug = {"name": "Ibuprofen", "dose": "200mg"}
ERRORS AND DEBUGGING
• Finding and fixing problems in code.
• Types: SyntaxError, NameError, Logical Error
INPUT AND OUTPUT
• Input: data from user, Output: information
shown to user.
• Example:
name = input("Enter name: ")
print("Hello, " + name)
COMMENTS
• Used to explain code without running it.
# This is a comment
print("Welcome")
OPERATORS
• Used for math and comparisons.
• Math: +, -, *, /, %, **
• Comparison: ==, !=, >, <
EXCEPTION HANDLING
• Avoid crashing by handling errors.
x = int(input("Enter number: "))
except ValueError:
print("Invalid input")
IMPORTING LIBRARIES
• Add functionality without writing from
scratch.
import math
print(math.sqrt(25))
PHARMACY USE CASE EXAMPLE
pharmacy_stock = ["Paracetamol",
"Ibuprofen"]
drug = input("Enter drug: ")
if drug in pharmacy_stock:
print("Available")
else:
print("Out of stock")