0% found this document useful (0 votes)
3 views7 pages

Python

It is an crash course part 1

Uploaded by

subhihafirdouz
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)
3 views7 pages

Python

It is an crash course part 1

Uploaded by

subhihafirdouz
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
You are on page 1/ 7

PYTHON

C R A S H C O U R S E

PAR T 1
Introduction to Python and
Computer Science
Fundamental

Welcome to the Introduction to Python and


Computer Science Fundamentals! In this
chapter, we will explore the basics of Python
programming and the fundamental concepts of
computer science.

First, let's talk about Python. Python is a high-


level, interpreted programming language that
is known for its simplicity and readability. It is
widely used in various fields such as web
development, data analysis, artificial
intelligence, and scientific computing.

2
One of the strengths of Python is its use of "English-
like" syntax, which makes it easier for beginners to
learn and understand. For example, to print "Hello,
World!" in Python, you can simply use the print()
function:

print("Hello, World!")
Python also has a vast library of modules and
packages that you can use to perform various tasks,
such as working with files, performing mathematical
calculations, and accessing the internet.

Now, let's dive into the fundamental concepts of


computer science. We will start by discussing
algorithms, which are step-by-step procedures for
solving problems. In computer science, algorithms are
often expressed using a pseudocode or a
programming language like Python.

For example, let's consider a simple algorithm for


finding the largest number in a list of numbers:

Assume that the first number in the list is the largest


number.
For each number in the list, do the following: a. If the
current number is larger than the largest number
found so far, set the largest number to the current
number.
When you have checked all the numbers, the largest
number is the one that you have found.

3
In Python, we can implement this algorithm as
follows:

def find_largest_number(numbers):
largest_number = numbers[0]
for number in numbers[1:]:
if number > largest_number:
largest_number = number
return largest_number

numbers = [5, 8, 1, 7, 3]
print(find_largest_number(numbers)) # Output: 8
In this example, the find_largest_number()
function takes a list of numbers as input and
returns the largest number in the list. We initialize
the largest_number variable to the first number in
the list, and then we iterate over the remaining
numbers in the list using a for loop. If we find a
number that is larger than the largest_number, we
update the largest_number variable. When we
have checked all the numbers, we return the
largest_number as the result.

Another important concept in computer science


is data structures, which are ways of organizing
and storing data in a computer. Common data
structures include arrays, linked lists, stacks,
queues, trees, and graphs.

For example, let's consider an array, which is a


collection of elements that are stored in
contiguous memory locations. Arrays provide
constant-time access to their elements, which 4
makes them useful for many applications.
In Python, we can create an array using the array()
function from the array module:

import array

numbers = array.array('i', [5, 8, 1, 7, 3])


print(numbers[0]) # Output: 5
print(numbers[4]) # Output: 3
In this example, we create an array of integers using the
array() function from the array module. We pass the
type code 'i' to indicate that we want to create an array
of integers, and we pass a list of integers as the initial
contents of the array. We can access the elements of the
array using their index numbers.

Finally, we will discuss the concept of computational


complexity, which is a measure of the amount of
resources (such as time or memory) required to solve a
problem using an algorithm. The computational
complexity of an algorithm is often expressed using big
O notation.

5
For example, let's consider the computational
complexity of the find_largest_number() function
that we saw earlier. The find_largest_number()
function has a time complexity of O(n), where n is
the number of elements in the input list. This is
because we need to check each element in the
list once to find the largest number.

On the other hand, the space complexity of the


find_largest_number() function is O(1), because
we only need to store the largest_number
variable, which has a constant size.

In summary, in this chapter, we have explored the


basics of Python programming and the
fundamental concepts of computer science,
including algorithms, data structures, and
computational complexity. We have also seen
examples of how to implement algorithms in
Python, using the print() function, for loops,
arrays, and other built-in features of the
language.

6
Part 1

7
PYTHON

You might also like