In previous classes, you learned the fundamentals of Python. Now it's time to explore more advanced features that make Python a powerful language for real-world applications.
Python's popularity has grown massively. It's now the most popular language for data science and artificial intelligence!
Create a program that reads a file of student grades and calculates the average.
1. Create a file called "grades.txt" with numbers (one per line).
2. Write a Python program that reads the file.
3. Calculate the average using a function.
4. Handle errors if the file doesn't exist or has invalid data.
You're building real-world applications!
Write a Python program that:
1. Reads a file called "students.txt" with names and grades.
2. Calculates the average grade.
3. Finds the highest and lowest grade.
4. Writes the results to a file called "report.txt".
5. Uses error handling to manage file errors.
Test your program with different input files.
Allah has given us the ability to create and solve problems.
The Qur'an says: "And We have certainly made the Qur'an easy to remember..." (54:17)
Just as we learn to handle errors in programming, we should learn to handle
challenges in life with patience and grace. Every error is an
opportunity to learn and grow.
Advanced Python includes functions with default arguments and variable arguments, lambda functions for one-line expressions, file handling to read and write data, and error handling using try/except blocks. These skills are essential for building robust, real-world applications.
Data structures are ways to organize and store data efficiently. Choosing the right data structure can make your programs faster and easier to write.
.append(), .extend(), .insert(), .remove(), .pop(), .sort().
The list is one of the most versatile data structures in Python. It can hold different data types and is used in almost every Python program.
.keys(), .values(), .items(), .get(), .update().
|), intersection (&), difference (-).
When would you use each data structure?
List: When you need an ordered collection that can change.
Tuple: When you need an ordered collection that won't change.
Dictionary: When you need to look up values by key.
Set: When you need unique values and don't care about order.
Choosing the right data structure makes your code better!
Write a Python program that:
1. Creates a list of 10 random numbers.
2. Uses a set to find the unique numbers.
3. Uses a dictionary to count the frequency of each number.
4. Uses a tuple to store a student's name, age, and grade.
Print the results of each data structure.
Allah has created the universe with order and organization.
The Qur'an says: "And everything with Him is by measure." (13:8)
Data structures help us organize information in a logical way.
This reflects the wisdom and order in Allah's creation.
When we organize data well, we are following this divine principle.
Data structures organize data efficiently. Lists are ordered and mutable. Tuples are ordered and immutable. Dictionaries store key-value pairs. Sets store unique, unordered elements. Choosing the right data structure is key to writing efficient code.
An algorithm is a step-by-step procedure for solving a problem. In computer science, we study algorithms to make our programs faster and more efficient.
Bubble sort is one of the simplest sorting algorithms, but it's also one of the slowest. For large datasets, faster algorithms like Quick Sort are used.
Compare the speed of different algorithms:
1. Create a list of 1000 random numbers.
2. Sort it using bubble sort, selection sort, and insertion sort.
3. Time each algorithm using Python's time module.
Which is fastest? Why?
Implement and test these algorithms:
1. Write bubble sort, selection sort, and insertion sort functions.
2. Test them with lists of different sizes (10, 100, 1000).
3. Count the number of comparisons each algorithm makes.
4. Write a report comparing the three algorithms.
What do you notice about the time complexity?
Algorithms teach us about efficiency and problem-solving.
The Qur'an says: "And We have made everything with measure." (54:49)
Just as we optimize algorithms to run faster, we should optimize our lives
by using our time and resources wisely. Efficiency is a virtue.
Algorithms are step-by-step procedures for solving problems. Sorting algorithms include bubble sort, selection sort, and insertion sort. Searching algorithms include linear search and binary search. Binary search is much faster than linear search for sorted data. Understanding algorithms helps you write efficient programs.
In previous classes, you learned about the components of a computer. Now let's go deeper into computer architecture – how the components are designed and how they work together.
The first CPU, the Intel 4004, was released in 1971 and had 2,300 transistors. Modern CPUs have billions of transistors!
Why does your computer slow down when you open too many programs?
When you open many programs, they compete for limited resources:
• CPU time – The CPU has to switch between programs.
• RAM – Your computer may run out of RAM and use slower storage.
• Cache – The cache can't hold all the data, so it's less effective.
Understanding architecture helps you optimize performance!
Research the architecture of your computer:
1. What CPU does your computer have?
2. How many cores does it have?
3. How much RAM do you have?
4. What type of storage (HDD or SSD)?
5. How fast is your CPU (GHz)?
Write a short report about your computer's architecture.
The complexity of computer architecture is a sign of Allah's creation.
The Qur'an says: "And We have certainly created man in the best of forms." (95:4)
Just as computers have complex systems that work together, our bodies have
systems (nervous, circulatory, etc.) that work together perfectly.
This is a sign of Allah's power and wisdom.
Computer architecture describes how components are designed and work together. The CPU uses the fetch-decode-execute cycle. Cache is fast memory for frequently used data. RAM is the main memory. Storage is permanent memory. Interrupts and DMA manage input/output operations. Understanding architecture helps you optimize performance.
Software engineering is the systematic approach to developing, maintaining, and managing software. It's not just about writing code – it's about planning, designing, testing, and managing software projects.
The "Waterfall" model was the first formal SDLC model, introduced in 1970. Today, Agile methods are more popular because they allow for faster, more flexible development.
A team of students was building a school management system using Agile.
Instead of waiting until the end to see the final product, they:
• Planned in 2-week sprints – They decided what to build each sprint.
• Had daily stand-ups – 5-minute meetings to share progress.
• Showed working software – They demonstrated their progress every sprint.
• Adapted to feedback – The teachers gave feedback, and they changed the plan.
By the end of the semester, they had a working system!
The lesson: Agile methods help teams deliver value quickly
and respond to change. It's a more effective way to build software.
Plan a software project using the SDLC:
Choose a project: A library management system, a school app, or a to-do list app.
Write a plan covering:
1. Requirements (what the software should do).
2. Design (how it will work).
3. Implementation plan (what you will build first).
4. Testing plan (how you will test it).
5. Deployment plan (how you will release it).
Share your plan with your class.
Allah is the perfect planner. The Qur'an says:
"And He has made everything with measure." (54:49)
Software engineering teaches us to plan, organize, and execute
projects effectively. These are skills that help us in all areas of life.
When we plan well, we are following a divine principle.
Software engineering is the systematic development of software. The SDLC includes planning, analysis, design, implementation, testing, deployment, and maintenance. Agile is a flexible, iterative approach. Testing ensures quality and reliability. Software engineering is a disciplined approach to building software that meets users' needs.
As technology becomes more powerful, it's essential to consider the ethical implications of how we build and use it. Islam provides a comprehensive framework for ethical technology use.
The concept of intellectual property and giving credit to authors has roots in Islamic tradition. Scholars always cited their sources and acknowledged those who came before them.
A developer named Ahmed was asked to build an app that collected user data
for targeted advertising. He realized that the app would collect more data
than necessary and share it without clear consent.
He spoke to his manager and said: "I can build this app, but I don't feel comfortable
with how we're handling user data. We should be transparent about what we collect
and give users a real choice."
The manager respected Ahmed's honesty. They revised the app to be more
privacy-focused. The app was still successful, and users appreciated the transparency.
The lesson: Ethical developers speak up when they
see something wrong. They build technology that is honest, fair, and respectful
of users. This is what it means to be a Muslim technologist.
Write a code of ethics for a technology company:
Include:
1. How the company will protect user data.
2. How the company will ensure fairness in AI and algorithms.
3. How the company will give back to the community.
4. How the company will reduce its environmental impact.
Share your code of ethics with your class.
Allah has given us knowledge and power to use technology.
The Qur'an says: "And We have certainly honored the children of Adam..." (17:70)
With great power comes great responsibility. As Muslims,
we must ensure that technology is used for good, justice, and the benefit
of all humanity. Let us be leaders in ethical technology.
Islamic ethics guide the use of technology. Key principles include Tawhid, justice, respecting intellectual property, protecting privacy, and beneficence. Contemporary issues include AI bias, social media ethics, the digital divide, and environmental impact. As Muslims, we must be responsible and ethical in how we develop and use technology.
You've explored advanced Python programming, data structures, algorithms, computer architecture, software engineering, and Islamic ethics in technology. You are now equipped with foundational knowledge for advanced computer science studies and a career in technology! May Allah bless your learning and help you use technology for good!