Lesson - 2 Fundamentals Of Python

πŸ“’ Notes

1. Variables & Data Types

A variable is like a container that stores a value.
In Python, you don’t need to declare the type explicitly β€” Python figures it out automatically.

Main Data Types

  • int β†’ whole numbers (5, -10)
  • float β†’ decimal numbers (3.14, -2.5)
  • string β†’ text ("Hello Nency")
  • list β†’ collection of items ([1, 2, 3], ["apple", "banana"])
  • dict β†’ key-value pairs ({"drug": "Paracetamol", "price": 50})
drug_name = "Paracetamol" # string dose_mg = 500 # int price = 1.25 # float side_effects = ["Nausea", "Headache", "Dizziness"] # list drug_info = {"name": "Aspirin", "dose": 100, "category": "Painkiller"} # dict print("Drug:", drug_name) print("Dose (mg):", dose_mg) print("Price:", price) print("Side Effects:", side_effects) print("Drug Info:", drug_info)

2. Operators

Operators are symbols that let us do math or comparisons.

Arithmetic Operators

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • // (floor division β†’ integer result)
  • % (modulus β†’ remainder)
  • ** (exponent β†’ power)
a = 10 b = 3 print("Addition:", a + b) # 13 print("Subtraction:", a - b) # 7 print("Multiplication:", a * b) # 30 print("Division:", a / b) # 3.33 print("Floor Division:", a // b)# 3 print("Remainder:", a % b) # 1 print("Power:", a ** b) # 1000

Comparison Operators (True/False)

  • == equal to
  • != not equal
  • > greater than
  • < less than
  • >= greater or equal
  • <= less or equal

3. Input / Output Examples

Input β†’ take user data
Output β†’ show results

drug = input("Enter drug name: ") dose = int(input("Enter dose (mg): ")) price = float(input("Enter price ($): ")) print("\n--- Drug Details ---") print("Name:", drug) print("Dose:", dose, "mg") print("Price: $", price)

πŸ’¬ Ask a Question