0% found this document useful (0 votes)
1 views4 pages

Computer Programming With Python

camputer programminng

Uploaded by

chekrouneyousra4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Computer Programming With Python

camputer programminng

Uploaded by

chekrouneyousra4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Programming with Python

Master 1 — English

Introduction
This module introduces programming concepts through the lens of language and literature.
Using Python, students learn to process text, analyze vocabulary, manage linguistic data,
and automate repetitive tasks — skills that are directly applicable to research in English
studies.

Definition of Python :

Python is a high-level, interpreted programming language known for its simple, readable
syntax that mirrors English. Created by Guido van Rossum in 1991, it is a versatile,
general-purpose language used for automation tasks,Natural Language Processing ( AI of
the language),building Softwares.. . It is free, open-source, and highly popular for beginners.

Why This Module Matters


Text analysis — Automatically count word frequencies, find patterns, and analyze large
literary corpora.

Linguistic research — Process and clean raw text data for NLP, concordance building, and
stylistic studies.

Data organization — Store bibliographies, glossaries, and character metadata in structured,


searchable formats.

Automation — Eliminate repetitive manual tasks like find-and-replace across hundreds of


documents.

Key Definitions
Variable — A named container that stores a value, like a labelled box. Example: name =
"Orwell"

Data type — The nature of a value. Three main types:

●​ str — text, written in quotes: "Hello"


●​ int — whole number: 42
●​ float — decimal number: 15.5

Index — The position of an item in a list, starting at 0. So list[0] is the first element.

Loop — Repeats a block of code for each item in a collection. Essential for processing word
lists.

Function — A reusable block of code that takes input and returns output. Keeps programs
clean and modular.

Algorithm — A step-by-step procedure to solve a problem, like a recipe for your code.

Data Structures
List [ ] — An ordered sequence where order matters and duplicates are allowed. Example:
["Austen", "Dickens", "Woolf"]

Dictionary { } — Stores Key → Value pairs, exactly like a real dictionary: a word and its
meaning. Example: {"Metaphor": "A comparison without like or as"}

Set { } — An unordered collection with no duplicates. Perfect for counting unique words.
Example: {"the", "sun", "rises"}

Core Methods — Quick Reference


Method Type What it does Linguistic use

.append(x) List Adds x to the end Add a new author to a


bibliography

.remove(x) List Deletes the first occurrence of Remove a word from a corpus
x

.lower() Strin Converts all text to lowercase Standardize text before word
g count

.upper() Strin Converts all text to uppercase Format headings or titles


g

.split() Strin Breaks a string into a list of Tokenize a sentence for analysis
g words

.replace(a Strin Swaps every a with b Correct a word across a full text
, b) g
.pop(key) Dict Removes and returns the entry Delete a term from a glossary

set(list) Set Removes all duplicate items Count unique words in a


paragraph

Exercise 1 — Palindrome Checker


A palindrome is a word that reads the same forwards and backwards. Classic examples:
madam, racecar, level, civic.

The idea: reverse the word using the slice trick word[::-1] and compare it to the original.
If they match → palindrome!

# Palindrome checker
word = “radar”
clean = [Link]().replace(" ", "") # step 1: clean the word
reversed_word = clean[::-1] # step 2: reverse it
return clean == reversed_word # step 3: compare

# Test it

Output:

madam → Palindrome ✓
python → Not a palindrome ✗
racecar → Palindrome ✓
level → Palindrome ✓
hello → Not a palindrome ✗

Exercise 2 — Anagram Checker


Two words are anagrams if they contain exactly the same letters, just rearranged. Classic
examples: listen / silent, evil / vile, heart / earth.

The idea: sort both words alphabetically using sorted(). If the sorted versions are
identical → anagrams, because if two words share the same letters, sorting will produce the
same result.

You might also like