Skip to content

Commit efbb5e9

Browse files
committed
[SLUG] Transferring changes from Slug as of 2023-04-20 20:08:21 +0100.
0 parents  commit efbb5e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2759
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/__pycache__

.replit

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# The command that runs the program. If the interpreter field is set, it will have priority and this run command will do nothing
2+
run = "bash lib/intro.sh"
3+
4+
# The primary language of the repl. There can be others, though!
5+
language = "python3"
6+
entrypoint = "main.py"
7+
# A list of globs that specify which files and directories should
8+
# be hidden in the workspace.
9+
hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]
10+
11+
# Specifies which nix channel to use when building the environment.
12+
[nix]
13+
channel = "stable-22_11"
14+
15+
[env]
16+
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
17+
PATH = "${HOME}/${REPL_SLUG}/lib:${VIRTUAL_ENV}/bin"
18+
PYTHONPATH = "$PYTHONHOME/lib/python3.10:${VIRTUAL_ENV}/lib/python3.10/site-packages"
19+
REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/"
20+
MPLBACKEND = "TkAgg"
21+
POETRY_CACHE_DIR = "${HOME}/${REPL_SLUG}/.cache/pypoetry"
22+
23+
# Enable unit tests. This is only supported for a few languages.
24+
[unitTest]
25+
language = "python3"
26+
27+
# Add a debugger!
28+
[debugger]
29+
support = true
30+
31+
# How to start the debugger.
32+
[debugger.interactive]
33+
transport = "localhost:0"
34+
startCommand = ["dap-python", "main.py"]
35+
36+
# How to communicate with the debugger.
37+
[debugger.interactive.integratedAdapter]
38+
dapTcpAddress = "localhost:0"
39+
40+
# How to tell the debugger to start a debugging session.
41+
[debugger.interactive.initializeMessage]
42+
command = "initialize"
43+
type = "request"
44+
45+
[debugger.interactive.initializeMessage.arguments]
46+
adapterID = "debugpy"
47+
clientID = "replit"
48+
clientName = "replit.com"
49+
columnsStartAt1 = true
50+
linesStartAt1 = true
51+
locale = "en-us"
52+
pathFormat = "path"
53+
supportsInvalidatedEvent = true
54+
supportsProgressReporting = true
55+
supportsRunInTerminalRequest = true
56+
supportsVariablePaging = true
57+
supportsVariableType = true
58+
59+
# How to tell the debugger to start the debuggee application.
60+
[debugger.interactive.launchMessage]
61+
command = "attach"
62+
type = "request"
63+
64+
[debugger.interactive.launchMessage.arguments]
65+
logging = {}
66+
67+
# Configures the packager.
68+
[packager]
69+
language = "python3"
70+
ignoredPackages = ["unit_tests"]
71+
72+
[packager.features]
73+
enabledForHosting = false
74+
# Enable searching packages from the sidebar.
75+
packageSearch = true
76+
# Enable guessing what packages are needed from the code.
77+
guessImports = true
78+
79+
# These are the files that need to be preserved when this
80+
# language template is used as the base language template
81+
# for Python repos imported from GitHub
82+
[gitHubImport]
83+
requiredFiles = [".replit", "replit.nix", ".config", "venv"]
84+
85+
[languages]
86+
87+
[languages.python3]
88+
pattern = "**/*.py"
89+
90+
[languages.python3.languageServer]
91+
start = "pylsp"
92+
93+
[deployment]
94+
run = ["sh", "-c", "python3 main.py"]

000_START_HERE.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# The Perfect Crab Introduction to Programming
2+
3+
Welcome!
4+
5+
This is a series of exercises designed to help you learn the
6+
fundamentals of programming necessary to succeed in the
7+
Makers coding assessment. We'll be using Python, but the
8+
ideas will apply to any language.
9+
10+
## How do I get started?
11+
12+
Click the 'Fork' button to the right. This will open up the
13+
programming interface you will use to learn.
14+
15+
If you're confident using your own local development setup
16+
and you have Python 3 installed, you can clone this
17+
repository and work through it that way.
18+
19+
## How do I use the replit interface?
20+
21+
The interface is made by an organisation called replit. We
22+
will call it the replit IDE.
23+
24+
You will need to engage with three parts of it:
25+
26+
* The file panel on your left, working top to bottom.
27+
* The code panel (that's this one) where you'll read and
28+
write code.
29+
* The shell panel to the right, where you'll run code.
30+
31+
To set up and learn how to use the interface, please follow
32+
the [replit IDE setup video](#link-to-video). This video has
33+
subtitles.
34+
35+
You may find the default replit theme hard to read. We have
36+
created two themes which combine good contrast and
37+
readability. I would recommend you use one of them:
38+
39+
* [Makers Reader Theme (Light)](https://replit.com/theme/@neoeno/makers-reader)
40+
* [Makers Reader Theme (Dark)](https://replit.com/theme/@neoeno/makers-reader-dark)
41+
42+
## How to read the material
43+
44+
The learning materials are code. They look a bit like this:
45+
46+
```python
47+
def identity(num):
48+
return num
49+
50+
# This is a function. A function is a reusable block of code.
51+
```
52+
53+
The first two lines are code. This is what you will be
54+
learning how to create.
55+
56+
That last line starting with a `#` is a comment. We will
57+
talk you through the ideas behind the code using comments.
58+
59+
You should read through each file top to bottom.
60+
61+
## What if I would prefer to watch than to read?
62+
63+
There are video alternatives for each file that you can
64+
follow along with. You can find them as a link at the top of
65+
each file.
66+
67+
## I have some feedback about the material
68+
69+
[You can give us feedback
70+
here.](https://airtable.com/shrDOnkLFDkRiOHmU?prefill_Repository=IntroToProgramming)

010_comments.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Video alternative: ...
2+
3+
# Hello! Welcome to programming. My name is Kay and I will
4+
# guide you through these early steps.
5+
#
6+
# To begin, I'd like to share with you a little quote from a
7+
# writer called Italo Calvino, himself retelling a Chinese
8+
# story:
9+
#
10+
# "Among Chuang-tzu's many skills, he was an expert
11+
# draftsman. The king asked him to draw a crab. Chuang-tzu
12+
# replied that he needed five years, a country house, and
13+
# twelve servants. Five years later the drawing was still
14+
# not begun. "I need another five years," said Chuang-tzu.
15+
# The king granted them. At the end of these ten years,
16+
# Chuang-tzu took up his brush and, in an instant, with a
17+
# single stroke, he drew a crab, the most perfect crab ever
18+
# seen."
19+
#
20+
# Perhaps you have come to programming because you would
21+
# like to be good at it. Perhaps you know people, or you
22+
# have heard of people, who are really exceptional
23+
# programmers.
24+
#
25+
# You, very likely, are not this person yet. Like
26+
# Chuang-tzu, it will take you many years to reach the
27+
# effortless skill of an expert programmer.
28+
#
29+
# But every programmer has sat where you have sat, curious
30+
# and willing to learn. They have spent many hours getting
31+
# things wrong, being stuck, being confused. You will go
32+
# through this too.
33+
#
34+
# Every expert sat where you are sat. What they all have in
35+
# common? They kept going.
36+
#
37+
# So let's get started.
38+
#
39+
# What are we learning?
40+
# =====================
41+
#
42+
# We're going to learn the fundamentals of the programming
43+
# language Python. Most programming languages are quite
44+
# similar, so it doesn't matter much that this is Python.
45+
# The key ideas are the same.
46+
#
47+
# We're going to learn enough to succeed in the Makers
48+
# interview process. The ideas themselves are quite simple.
49+
# The complexity of programming is in the combination of
50+
# these ideas. Here's a list of what we'll learn:
51+
#
52+
# * Functions (making your own programs)
53+
# * Arithmetic (basic maths)
54+
# * Expressions and statements (the building blocks of
55+
# programs)
56+
# * Strings (letters and words)
57+
# * Conditionals (ifs)
58+
# * Lists (sequences of items)
59+
# * Loops (fors)
60+
# * Dicts (pairs of items)
61+
#
62+
# Each section will finish with a few exercises. We will
63+
# finish with some extra tricky exercises for you to test
64+
# your skills.
65+
#
66+
# By the way — these lines starting with the `#` key?
67+
# They're called comments. They don't get executed by the
68+
# program. You can create one yourself if you like.
69+
70+
# Type your name as a comment on the next line.
71+
72+
# Now open up `011_identity.py` and get started with some
73+
# real code!

011_identity.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Ignore this bit for now. It imports some helper code for
2+
# us.
3+
from lib.helpers import show_us_the_output_of
4+
5+
# Video alternative: ...
6+
7+
# Start reading here:
8+
9+
def identity(num):
10+
return num
11+
12+
# This is a function. A function is a reusable block of
13+
# code.
14+
#
15+
# Think of functions as little machines. It takes an input,
16+
# processes it in some way, and then returns an output.
17+
#
18+
# This `identity` function has:
19+
#
20+
# * A name: `identity` that we can use to call it
21+
# * A parameter: `num` that it takes as input
22+
# * A body: `return num` that returns the input as output
23+
#
24+
# `identity` is a very simple function, it doesn't do very
25+
# much. It takes a piece of data as input, and returns it as
26+
# output.
27+
#
28+
# Let's use it:
29+
30+
print("identity(4) is:") # <-- This just prints a message
31+
32+
show_us_the_output_of( # <-- This helps us see the output of...
33+
identity(4) # <-- This is the important part
34+
)
35+
36+
# @TASK: Run this program by opening the shell in the
37+
# right-hand panel and running:
38+
#
39+
# ```
40+
# python 011_identity.py
41+
# ```
42+
#
43+
# If you don't see the shell, watch this video to to get set
44+
# up: @TODO
45+
#
46+
# After running the command, you should see:
47+
#
48+
# ```
49+
# identity(4) is:
50+
# 4
51+
# ```
52+
#
53+
# This shows us that when we call the `identity` function
54+
# with the input parameter `4` — it gives us `4` back.
55+
#
56+
# Now move on to 012_add_one.py

012_add_one.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from lib.helpers import show_us_the_output_of
2+
3+
# Video alternative: ...
4+
5+
# Let's create a more useful function:
6+
7+
def add_one(num):
8+
return num + 1
9+
10+
# Here is how it used (but don't run it just yet):
11+
12+
print("add_one(6) is:")
13+
show_us_the_output_of(
14+
add_one(6) # <-- Calling the function
15+
)
16+
17+
# @TASK: Run this code in the shell:
18+
#
19+
# ```
20+
# python 012_add_one.py
21+
# ```
22+
23+
# `add_one` is a function (little machine) that takes an
24+
# input of a number, adds one to it, and then returns the
25+
# result.
26+
27+
# Now move on to 013_add_two.py

013_add_two.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from lib.helpers import check_that_these_are_equal
2+
3+
# Video alternative: ...
4+
5+
# Now you try. Here's an exercise for you:
6+
#
7+
# @TASK: Write a function called `add_two` that:
8+
#
9+
# * Takes a number as input
10+
# * Adds two to it
11+
# * Returns the result
12+
13+
# YOUR FUNCTION GOES BELOW THIS LINE
14+
15+
16+
17+
# YOUR FUNCTION GOES ABOVE THIS LINE
18+
19+
# @TASK: To check your work, run this in the shell:
20+
# python 013_add_two.py
21+
22+
# This will run the test at the bottom of this file.
23+
24+
# If you have trouble, look back at `add_one` _very_
25+
# closely, symbol by symbol, to see if you can see any
26+
# differences to your version. Pay particular attention to
27+
# the `:` at the end of the first line, and the spacing at
28+
# the start of some of the lines.
29+
30+
print("add_two(6) is:")
31+
32+
check_that_these_are_equal(
33+
add_two(6),
34+
8
35+
)
36+
37+
# When you're done, move on to 014_multiply_numbers.py

014_multiply_numbers.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from lib.helpers import show_us_the_output_of
2+
3+
# Video alternative: ...
4+
5+
# So far we've seen functions that take only one input. They
6+
# can actually take two, or even more, inputs. Take a look
7+
# at this:
8+
9+
# Notice two items and the comma below
10+
def multiply_numbers(num_a, num_b):
11+
return num_a * num_b # That `*` means multiply_numbers
12+
13+
# And let's use it:
14+
15+
print("multiply_numbers(2, 3) is:")
16+
17+
show_us_the_output_of(
18+
multiply_numbers(2, 3)
19+
)
20+
21+
print("multiply_numbers(3, 5) is:")
22+
23+
show_us_the_output_of(
24+
multiply_numbers(3, 5)
25+
)
26+
27+
# @TASK: Run these in the shell using:
28+
# python 014_multiply_numbers.py
29+
30+
# As a reminder, these inputs are called parameters.
31+
32+
# Now move on to 015_add_numbers.py to write your own.

0 commit comments

Comments
 (0)