Input & Output in Python for Pharmacy Students (Patient Data Entry & Report Generation)
Input and Output (I/O) operations are fundamental in Python programming. In pharmaceutical applications, they are used to collect patient data, process clinical information, and generate reports.
๐ท What is Input in Python?
Input allows users to enter data into a program using the input() function.
name = input("Enter patient name: ")
๐ท Converting Input Data
Since input() returns string, we need type conversion for calculations.
age = int(input("Enter age: "))
weight = float(input("Enter weight: "))
๐ท What is Output in Python?
Output is displayed using the print() function.
print("Patient Name:", name)
๐ท Formatting Output
Formatted output improves readability.
print(f"Patient {name} is {age} years old")
๐ Patient Data Entry Example
name = input("Enter patient name: ")
weight = float(input("Enter weight (kg): "))
dose_per_kg = 10
total_dose = weight * dose_per_kg
print(f"Total dose for {name} is {total_dose} mg")
๐ Simple Patient Report
name = input("Enter patient name: ")
age = int(input("Enter age: "))
drug = input("Enter drug name: ")
print("----- Patient Report -----")
print("Name:", name)
print("Age:", age)
print("Drug:", drug)
๐ง Memory Tricks
- input() โ Takes data
- print() โ Displays data
- int() / float() โ Converts data
๐งช Practice Exercise
Create a program that:
- Takes patient weight
- Calculates dose (5 mg/kg)
- Prints result
๐ MCQs
- input() returns:
a) int
b) float
c) string
d) bool
Answer: c - Which function displays output?
a) input()
b) print()
c) show()
d) display()
Answer: b - Which function converts string to integer?
a) str()
b) int()
c) float()
d) bool()
Answer: b
โ FAQs
Why is type conversion required?
Because input() takes data as string, conversion is needed for calculations.
Where is input-output used in pharmacy?
In patient data entry, clinical reports, and data processing systems.
๐ฅ Download Patient Data Practice Exercises
Includes real-world pharma scenarios.
โก Next Topic: String Manipulation in Python โ
Unit 1 Blog Series:
- Installing Python
- Installing IDEs like Jupyter, VS Code, PyCharm
- Variables and Data types in Python
- Operators in Python
- Input & Output (You are on this page page)
- String Manipulation
- Libraries in Python
Question Bank : Unit 1 Python Programming Basics
For more details: Basics of Python Programming for Pharmaceutical Sciences (Theory)