Tasks
Python is a dynamic, interpreted language that has gained widespread popularity among developers for its ease of use and versatility. It was first released in 1991 by Guido van Rossum and has since become one of the most widely-used languages in the world.
Python's syntax is clear and concise, making it easy to read and write, even for those new to programming. Its standard library includes a wide range of modules, making it well-suited for tasks ranging from web development and data analysis to artificial intelligence and machine learning.
With its focus on simplicity and flexibility, Python is a great language for both beginners and experienced developers alike, which is why it's such a good choice for an Applied Computer Science course.
You will require a code editor supporting Python syntax (e.g., Visual Studio Code with plugins / LunarVIM) and a Python 3 (>= 3.7) distribution for your Operating System.
Windows users, you can either use the official Python3 release installer or the Windows Subsystem for Linux (highly recommended).
For Linux-based OSes, you may simply install the python3
and python3-pip
packages from the distro's official repositories.
Most of these tasks will involve a specific subset of Python features (e.g., data types, standard library routines or even PIP packages).
For most of them, you will be given a couple of notes with the concepts you will need to use and, optionally, an URL to their official documentations. Also check out the official Python Tutorial (at least take a look at its Table of Contents to get a sense of the available topics).
Even when you're writing Python scripts, you'll want to do some quick prototyping every now and again. The shell that you choose for this can either make or break your experience. We recommend that you install IPython:
$ sudo apt update && sudo apt upgrade $ sudo apt install ipython3 $ ipython3
First, let's familiarize ourselves with Python's string type:
input()
); next sub-tasks will use this value and apply various string transformations on it;n
positions to the: right for encryption, left for decryption); use the number 17
' for testing!
ord()
built-in function to get the ASCII code of a character (as int
);Z + 1 ⇒ A
!
Python is also popular for its numeric manipulation features (it can handle very large numbers!). Let's find out:
int
!);13568 ⇒ 86531
)!generate_prime(k)
, which takes in an argument and will generate a prime number of exactly k
digits; use it to generate a 15-digit prime number (decrease this if it's taking too long :(
)!
Solve these subtasks all in the same file (use print()
statements to display the results):
Use the following list:
sample = ["a", 90, 8, "X55", "1z", 102, "asdf", 65, 10, "word", "567", 567]
Well:
int
type values should remain)… can you make it using a single line of code? now it's the time to introduce list comprehensions;
m = [[1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2], [2, 3, 4, 1]]
First, take a couple (3-4) of paragraphs from here and store them inside a .txt
file.
dict
with each word from this text (lower cased as key), counting their frequency (as its value);[('the', 29), ('of', 18), ('and', 15), ('to', 10), ('a', 9)]
What else can you do easily using Python… ?
Let's try this one:
requests
library!
(Note: you must first install it using pip
).
<br>
line break tags, replace them with newlines instead).
Instead: simply use the standard string search methods and Python sequence indexing / slices to accomplish this much easier ;)