BP101T Important Questions: Unit I with model answers

Unit I: Introduction to Python programming

The most important Unit I questions, arranged by the PCI exam pattern, with model answers written the way examiners expect.

PCI exam pattern · 75 marks

  • Multiple choice questions20 × 1 = 20 marks
  • Long answers (answer 2 of 3)2 × 10 = 20 marks
  • Short answers (answer 7 of 9)7 × 5 = 35 marks

Expected questions based on the PCI syllabus. BP101T is a new subject, so there are no previous-year papers yet; actual university questions may differ.

Long answer questions (10 marks)

Q1

Explain the features of Python and its applications in pharmaceutical sciences.

▶Show model answer

Introduction: Python is a high-level, general-purpose programming language created by Guido van Rossum and first released in 1991. It is one of the most widely used languages for data analysis, automation and artificial intelligence.

Features of Python:

  1. Simple and readable: its syntax is close to English, so programs are easy to write, read and learn.
  2. Interpreted: code is executed statement by statement by the Python interpreter, which makes testing and finding mistakes easy. (Internally, Python first converts code into bytecode, which the Python Virtual Machine runs.)
  3. High-level: the programmer does not need to manage memory or hardware details.
  4. Free and open source: anyone can use, share and modify it at no cost.
  5. Portable (cross-platform): the same program runs on Windows, macOS and Linux.
  6. Dynamically typed: the data type of a value is decided automatically when the program runs; it does not have to be declared.
  7. Large standard library and third-party libraries: for example NumPy, Pandas and Matplotlib for data analysis and graphs.
  8. Supports object-oriented programming and has a large, active community.

Applications in pharmaceutical sciences:

  1. Clinical trial data analysis: cleaning, summarising and analysing patient data.
  2. Pharmacokinetics: calculating parameters such as Cmax, Tmax and AUC and plotting concentration–time curves.
  3. Pharmacovigilance: analysing adverse drug reaction (ADR) reports to detect safety signals.
  4. Computer-aided drug design (CADD) and cheminformatics: handling molecular structures and predicting drug properties (e.g. with RDKit).
  5. Automation: generating lab reports, labels and dosage calculations.
  6. Machine learning and AI: predicting drug activity and supporting drug discovery.

Conclusion: Because it is easy to learn and has powerful libraries, Python is the preferred language for data work in the pharmaceutical industry.

Q2

Explain the steps to install Python and an IDE. List the advantages of using an IDE over a simple text editor.

▶Show model answer

Installing Python (Windows):

  1. Download the latest Python 3 installer from python.org.
  2. Run the installer and tick "Add python.exe to PATH".
  3. Click Install Now and complete the installation.
  4. Verify the installation by typing python --version in Command Prompt.

(On macOS, download the installer from python.org; most Linux systems already include Python 3.)

Installing an IDE:

  • Jupyter Notebook: install the Anaconda distribution, which includes Python and Jupyter, then launch Jupyter Notebook. Google Colab offers the same notebook online, with no installation.
  • PyCharm: download the free Community edition from JetBrains and select the installed Python interpreter.
  • VS Code: download it from Microsoft, install the Python extension and select the interpreter.

IDE (Integrated Development Environment): a software application that combines a code editor, tools to run programs, error checking and a debugger in one place.

Advantages of an IDE over a text editor:

  1. Syntax highlighting: code is coloured, making it easier to read.
  2. Auto-completion: suggests keywords and names while typing.
  3. Error detection: highlights mistakes before the program is run.
  4. Integrated execution: programs run with one click and the output appears in the same window.
  5. Debugging tools: breakpoints and step-by-step execution help find errors.
  6. Project management: organises multiple files and folders.
  7. Package management: libraries and extensions can be installed easily.
Q3

Explain variables and the basic data types in Python with pharmaceutical examples. Add a note on type casting.

▶Show model answer

Variables: A variable is a named location in memory that stores a value. A value is assigned using =, for example weight_kg = 52.5. The value can be changed later by assigning a new value, and Python decides the data type automatically.

Basic data types:

  1. Integer (int): whole numbers without a decimal point. Example: tablets_per_strip = 10
  2. Float (float): numbers with a decimal point. Example: weight_kg = 52.5
  3. String (str): a sequence of characters in quotes. Example: drug_name = "Paracetamol"
  4. Boolean (bool): only two values, True or False. Example: prescription_verified = True

The function type() returns the data type of a value:

print(type(10))            # <class 'int'>
print(type(52.5))          # <class 'float'>
print(type("Paracetamol")) # <class 'str'>
print(type(True))          # <class 'bool'>

Type casting (type conversion): changing a value from one data type to another.

  • Implicit conversion: Python converts automatically, e.g. 10 + 2.5 gives 12.5 (int becomes float).
  • Explicit conversion: the programmer converts using int(), float(), str() and bool().
dose = int("500")        # str to int: 500
weight = float("52.5")   # str to float: 52.5
label = str(250) + " mg" # int to str: "250 mg"

int() removes the decimal part: int(52.9) gives 52. Converting text that is not a number, such as int("abc"), causes a ValueError.

Rules for naming variables: letters, digits and underscore only; must not start with a digit; no spaces; case-sensitive; keywords such as if and True cannot be used.

Q4

Explain the different types of operators in Python with suitable examples.

▶Show model answer

An operator is a symbol that performs an operation on values (called operands).

1. Arithmetic operators

OperatorMeaningExampleResult
+Addition500 + 250750
-Subtraction30 - 1218
*Multiplication500 * 31500
/Division (always float)10 / 42.5
//Floor division10 // 42
%Modulus (remainder)10 % 42
**Exponent (power)2 ** 38

2. Comparison (relational) operators: compare two values and give True or False: ==, !=, >, <, >=, <=. Example: dose_mg > 4000 gives True if the dose exceeds 4000 mg.

3. Logical operators: combine conditions: and (both must be True), or (at least one True), not (reverses the result). Example: age >= 18 and weight_kg >= 50.

4. Assignment operators: store values: =, +=, -=, *=, /=. Example: stock = 100 then stock -= 10 makes stock equal to 90.

5. Membership operators: in and not in check whether a value is present. Example: "cin" in "Amoxicillin" gives True.

6. Identity operators: is and is not check whether two names refer to the same object.

Operator precedence: ** is evaluated first, then *, /, //, %, then + and -; brackets () override this order.

Example: daily dose calculation

weight_kg = 60
dose_per_kg = 15          # mg per kg
doses_per_day = 3
daily_dose = weight_kg * dose_per_kg * doses_per_day
print("Daily dose:", daily_dose, "mg")   # Daily dose: 2700 mg
print(daily_dose <= 4000)                # True
Q5

Explain the input() and print() functions in Python. Write a program to calculate the dose of a drug from the patient's body weight.

10 marksLearn this in Lesson 1.5 · lesson coming soon
▶Show model answer

input() function: reads a line typed by the user from the keyboard. It can display a message (prompt). It always returns a string, so the value must be converted using int() or float() before calculations.

name = input("Enter patient name: ")
weight = float(input("Enter weight in kg: "))

print() function: displays output on the screen.

  • Several items can be printed, separated by commas; a space is added between them.
  • sep changes the separator: print("A", "B", sep="-") gives A-B.
  • end changes what is printed at the end (a new line by default): print("Dose", end=": ").
  • f-strings insert values into text: print(f"Dose: {dose} mg").

Program: dose from body weight

# Dose calculation from body weight
name = input("Patient name: ")
weight_kg = float(input("Body weight (kg): "))
dose_per_kg = float(input("Dose (mg per kg): "))

dose_mg = weight_kg * dose_per_kg

print(f"Patient: {name}")
print(f"Dose: {dose_mg} mg")

Sample run:

Patient name: Ravi
Body weight (kg): 20
Dose (mg per kg): 15
Patient: Ravi
Dose: 300.0 mg

Explanation: input() reads the values as text, float() converts them to numbers, the dose is calculated with *, and print() with f-strings displays the result.

Q6

What is a string? Explain string indexing, slicing and common string operations with examples.

10 marksLearn this in Lesson 1.6 · lesson coming soon
▶Show model answer

String: a sequence of characters enclosed in single, double or triple quotes, e.g. drug = "Amoxicillin". Strings are immutable: their characters cannot be changed after creation.

Indexing: each character has a position (index) starting from 0. Negative indexes count from the end, starting at -1.

drug = "Aspirin"
print(drug[0])    # A
print(drug[3])    # i
print(drug[-1])   # n

Slicing: string[start:stop] returns characters from start up to, but not including, stop.

print(drug[0:3])  # Asp
print(drug[3:])   # irin
print(drug[:4])   # Aspi

Common operations:

  1. Concatenation (+): "Para" + "cetamol" gives "Paracetamol".
  2. Repetition (*): "-" * 10 gives ten dashes.
  3. Length: len("Insulin") gives 7.
  4. Membership: "cin" in "Amoxicillin" gives True.

Common string methods:

MethodExampleResult
upper()"aspirin".upper()ASPIRIN
lower()"ASPIRIN".lower()aspirin
strip()" insulin ".strip()insulin
replace()"500 mg".replace("mg", "MG")500 MG
split()"Paracetamol,500,mg".split(",")['Paracetamol', '500', 'mg']
find()"Aspirin".find("pi")2

Pharmaceutical use: cleaning drug names typed in different cases, reading values from labels and generating standard label text.

Q7

What are modules, packages and libraries in Python? Explain how to install and use them with pip, and name important libraries for pharmaceutical sciences.

10 marksLearn this in Lesson 1.7 · lesson coming soon
▶Show model answer

Module: a single Python file (.py) containing functions and variables that can be reused, e.g. math, random.

Package: a collection of related modules organised in a folder.

Library: a collection of packages and modules for a particular purpose, e.g. NumPy for numerical work.

Importing:

import math
print(math.sqrt(16))          # 4.0

from math import pi
print(pi)                     # 3.141592653589793

import numpy as np            # np is a short alias

pip (package installer for Python): the standard tool to install third-party packages from PyPI (Python Package Index). It is run in the Command Prompt or terminal, not inside a Python program:

TaskCommand
Installpip install pandas
Install a specific versionpip install pandas==2.2.0
Upgradepip install --upgrade pandas
Uninstallpip uninstall pandas
List installed packagespip list

In Jupyter Notebook or Google Colab, prefix the command with !, e.g. !pip install rdkit.

Important libraries for pharmaceutical sciences:

  1. NumPy: fast numerical calculations and arrays.
  2. Pandas: reading and analysing tables of data (CSV, Excel), e.g. clinical trial data.
  3. Matplotlib: graphs such as concentration–time curves.
  4. SciPy: scientific calculations, curve fitting and statistics.
  5. scikit-learn: machine learning models.
  6. RDKit: cheminformatics, handling molecules and calculating descriptors.

Short answer questions (5 marks)

Q8

What is an interpreter? Explain how a Python program is executed.

▶Show model answer

An interpreter is a program that reads source code and executes it statement by statement. Python uses an interpreter, so it is called an interpreted language.

How a Python program runs:

  1. The programmer writes source code in a .py file.
  2. The Python interpreter reads the program line by line, from top to bottom.
  3. Internally, the code is converted into bytecode, which the Python Virtual Machine (PVM) executes.
  4. The output of each statement appears as it runs.
  5. If a line has an error, execution stops at that line and an error message is shown; the lines before it have already run.
Q9

Differentiate between a compiler and an interpreter.

▶Show model answer
CompilerInterpreter
Translates the whole program into machine code before running it.Translates and executes the program statement by statement.
Errors are reported after the whole program is checked.Execution stops at the first error.
Produces a separate executable file.No separate executable file is produced.
The compiled program usually runs faster.Usually slower, but easier to test and correct.
Examples: C, C++.Examples: Python, JavaScript.
Q10

What is an IDE? Compare Jupyter Notebook, PyCharm and VS Code.

▶Show model answer

An IDE (Integrated Development Environment) is a software application that combines a code editor, tools to run programs, error checking and a debugger in one place.

Jupyter NotebookPyCharmVS Code
TypeWeb-based notebookFull IDE for PythonLight code editor with extensions
Code runs inSeparate cellsWhole filesWhole files (notebooks via extension)
Best forData analysis, graphs, teachingLarge Python projectsMany languages, general use
Get it fromAnaconda or Google ColabJetBrains (free Community edition)Microsoft (free)
Q11

State the rules for naming variables in Python with valid and invalid examples.

▶Show model answer
  1. Names may contain letters, digits and underscores (_) only.
  2. A name must not begin with a digit.
  3. Spaces and special characters such as -, @ and % are not allowed.
  4. Names are case-sensitive: dose and Dose are different variables.
  5. Keywords such as if, for, True and class cannot be used as names.
  6. Names should be meaningful, e.g. patient_weight_kg rather than x.
ValidInvalidReason
dose_mgdose-mg- not allowed
drug22drugstarts with a digit
_countdrug namecontains a space
Weightforkeyword
Q12

What is type casting? Explain implicit and explicit type conversion with examples.

▶Show model answer

Type casting means converting a value from one data type to another.

1. Implicit conversion: done automatically by Python, usually to avoid losing information.

total = 10 + 2.5     # int + float
print(total)         # 12.5 (float)

2. Explicit conversion: done by the programmer using int(), float(), str() and bool().

tablets = int("30")         # "30" to 30
weight = float("52.5")      # "52.5" to 52.5
label = str(500) + " mg"    # 500 to "500 mg"
print(int(7.9))             # 7 (decimal part removed)

Explicit conversion is needed because input() always returns a string. Converting non-numeric text, e.g. int("ten"), raises a ValueError.

Q13

Explain operator precedence in Python with an example.

▶Show model answer

Operator precedence is the order in which Python evaluates operators in an expression.

Order (highest to lowest):

  1. () brackets
  2. ** exponent
  3. *, /, //, %
  4. +, -
  5. Comparison operators: ==, !=, >, <, >=, <=
  6. not, then and, then or

Operators of the same level are evaluated from left to right (except **, which is evaluated from right to left).

Example:

print(10 + 5 * 2)      # 20  (5 * 2 first)
print((10 + 5) * 2)    # 30  (brackets first)
print(2 ** 3 * 2)      # 16  (2 ** 3 first)
print(100 - 20 / 4)    # 95.0

Using brackets makes calculations such as dose formulas clear and avoids mistakes.

Q14

Differentiate between / and //, and between = and == in Python.

▶Show model answer

/ and //:

/ (division)// (floor division)
Gives the exact resultGives the result rounded down to a whole number
Result is always a floatResult is an int when both values are int
10 / 4 gives 2.510 // 4 gives 2

Example: number of full strips from 25 tablets with 10 per strip: 25 // 10 gives 2.

= and ==:

= (assignment)== (comparison)
Stores a value in a variableChecks whether two values are equal
dose = 500dose == 500
Does not produce a resultProduces True or False
Q15

Write a Python program to read a patient's body weight and calculate the single dose of paracetamol at 15 mg/kg.

5 marksLearn this in Lesson 1.5 · lesson coming soon
▶Show model answer
# Paracetamol dose at 15 mg per kg
weight_kg = float(input("Enter body weight (kg): "))
dose_mg = weight_kg * 15
print(f"Single dose of paracetamol: {dose_mg} mg")

Sample output:

Enter body weight (kg): 20
Single dose of paracetamol: 300.0 mg

Explanation:

  1. input() reads the weight as a string.
  2. float() converts it to a number with a decimal point.
  3. The dose is calculated by multiplying weight by 15.
  4. print() with an f-string displays the result.
Q16

Explain string indexing and slicing in Python with examples.

5 marksLearn this in Lesson 1.6 · lesson coming soon
▶Show model answer

Indexing: every character in a string has a position number (index). The first character has index 0; negative indexes count from the end, starting at -1.

drug = "Insulin"
print(drug[0])    # I
print(drug[2])    # s
print(drug[-1])   # n

Slicing: string[start:stop] returns the characters from start up to, but not including, stop. If start is left out, slicing begins at 0; if stop is left out, it goes to the end.

print(drug[0:3])  # Ins
print(drug[3:])   # ulin
print(drug[:2])   # In
print(drug[-3:])  # lin

Using an index outside the string, e.g. drug[10], causes an IndexError.

Q17

What are comments in Python? Why are they used? Give examples.

▶Show model answer

Comments are notes written in a program for humans to read. Python ignores them while running the program.

Single-line comment: starts with #.

# Calculate the daily dose
daily_dose = 500 * 3   # 500 mg three times a day

Multi-line comments: each line starts with #. A triple-quoted string (""" ... """) is also commonly used to write longer notes, such as a description at the top of a program.

Uses of comments:

  1. Explain what the code does and why.
  2. Make programs easier to read and maintain.
  3. Temporarily disable a line while testing.
  4. Record details such as the author, date and units (mg, kg).
Q18

What is pip? Explain the commands to install, upgrade, uninstall and list packages.

5 marksLearn this in Lesson 1.7 · lesson coming soon
▶Show model answer

pip (package installer for Python) is the standard tool used to download and install third-party packages from the Python Package Index (PyPI). It is included with Python 3 and is run in the Command Prompt or terminal.

TaskCommand
Install a packagepip install numpy
Install a specific versionpip install numpy==1.26.4
Upgrade a packagepip install --upgrade numpy
Uninstall a packagepip uninstall numpy
List installed packagespip list
Show details of a packagepip show numpy

In Jupyter Notebook or Google Colab, add ! before the command, e.g. !pip install pandas. After installing, the package is used in a program with import, e.g. import numpy as np.

Q19

Explain formatted output in Python using f-strings, sep and end, with examples.

5 marksLearn this in Lesson 1.5 · lesson coming soon
▶Show model answer

f-strings: a string with f before the quotes; values inside {} are inserted into the text.

drug = "Amoxicillin"
dose = 500
print(f"{drug}: {dose} mg")      # Amoxicillin: 500 mg
print(f"Daily: {dose * 3} mg")   # Daily: 1500 mg
print(f"{2/3:.2f}")              # 0.67 (two decimal places)

sep: sets the separator between items (a space by default).

print("12", "05", "2026", sep="/")   # 12/05/2026

end: sets what is printed at the end (a new line by default).

print("Dose", end=": ")
print("500 mg")                      # Dose: 500 mg

Formatted output is used to print clear labels, reports and prescriptions.

Multiple choice questions (1 marks)

1.Python was created by:

  1. A.Dennis Ritchie
  2. B.Guido van Rossum
  3. C.James Gosling
  4. D.Bjarne Stroustrup
Show answer

Answer: B. Guido van RossumGuido van Rossum created Python and released it in 1991.

2.Python is an example of a/an:

  1. A.Interpreted language
  2. B.Compiled-only language
  3. C.Assembly language
  4. D.Machine language
Show answer

Answer: A. Interpreted languagePython code is executed statement by statement by the Python interpreter.

3.Which symbol starts a single-line comment in Python?

  1. A.//
  2. B./*
  3. C.--
  4. D.#
Show answer

Answer: D. #Everything after # on a line is ignored by Python.

4.Which tool runs Python code in separate cells?

  1. A.Notepad
  2. B.Command Prompt
  3. C.Jupyter Notebook
  4. D.MS Word
Show answer

Answer: C. Jupyter NotebookJupyter Notebook (and Google Colab) run code in cells, with output below each cell.

5.IDE stands for:

  1. A.Internal Data Editor
  2. B.Integrated Development Environment
  3. C.Interactive Design Engine
  4. D.Integrated Debugging Editor
Show answer

Answer: B. Integrated Development EnvironmentAn IDE combines an editor, running, error checking and debugging in one place.

6.What is the output of type(52.5)?

  1. A.<class 'float'>
  2. B.<class 'int'>
  3. C.<class 'str'>
  4. D.<class 'bool'>
Show answer

Answer: A. <class 'float'>A number with a decimal point is a float.

7.Which of these is a valid variable name?

  1. A.2dose
  2. B.dose-mg
  3. C.for
  4. D.dose_mg
Show answer

Answer: D. dose_mgNames may use letters, digits and underscores, must not start with a digit and cannot be keywords.

8.Which of these is a Boolean value?

  1. A."True"
  2. B.1.0
  3. C.True
  4. D.'yes'
Show answer

Answer: C. TrueTrue and False (without quotes) are the two Boolean values. "True" in quotes is a string.

9.What is the result of 7 // 2?

  1. A.3.5
  2. B.3
  3. C.4
  4. D.1
Show answer

Answer: B. 3Floor division gives the result rounded down to a whole number.

10.What is the result of 7 % 2?

  1. A.1
  2. B.3
  3. C.3.5
  4. D.0
Show answer

Answer: A. 1% gives the remainder: 7 divided by 2 leaves 1.

11.What is the result of 2 ** 3?

  1. A.6
  2. B.5
  3. C.9
  4. D.8
Show answer

Answer: D. 8** is the exponent operator: 2 × 2 × 2 = 8.

12.What is the result of 10 / 4?

  1. A.2
  2. B.2.0
  3. C.2.5
  4. D.3
Show answer

Answer: C. 2.5/ always gives a float with the exact result.

13.What is the result of int("500") + 5?

  1. A."5005"
  2. B.505
  3. C.Error
  4. D.500
Show answer

Answer: B. 505int("500") converts the text to the number 500, so the sum is 505.

14.Which operator checks whether two values are equal?

  1. A.==
  2. B.=
  3. C.!=
  4. D.=>
Show answer

Answer: A. ==== compares values; = stores a value in a variable.

15.The input() function always returns a value of type:

  1. A.int
  2. B.float
  3. C.bool
  4. D.str
Show answer

Answer: D. strinput() returns text, so it must be converted with int() or float() for calculations.

16.What is the output of print("A", "B", sep="-")?

  1. A.A B
  2. B.AB
  3. C.A-B
  4. D.A,B
Show answer

Answer: C. A-Bsep sets the separator printed between the items.

17.If drug = "Aspirin", what is drug[-1]?

  1. A.A
  2. B.n
  3. C.i
  4. D.Error
Show answer

Answer: B. nIndex -1 is the last character of the string.

18.What is the output of len("Insulin")?

  1. A.7
  2. B.6
  3. C.8
  4. D.5
Show answer

Answer: A. 7"Insulin" has 7 characters.

19.What is the result of "Dose" * 2?

  1. A.Dose2
  2. B.Error
  3. C.Dose Dose
  4. D.DoseDose
Show answer

Answer: D. DoseDose* repeats a string the given number of times.

20.Which command installs the pandas library?

  1. A.python install pandas
  2. B.import pandas
  3. C.pip install pandas
  4. D.install pandas
Show answer

Answer: C. pip install pandaspip install downloads and installs a package; import only loads an installed one.

Updated 2026-10-28