P Y T H O N I N H I G H S C H O O L
A R N A U D B O D I N
A L G O R I T H M S A N D M AT H E M AT I C S
Exo7
Python in high school
Let’s go!
Everyone uses a computer, but it’s another thing to drive it! Here you will learn the basics of programming.
The objective of this book is twofold: to deepen mathematics through computer science and to master
programming with the help of mathematics.
Python
Choosing a programming language to start with is tricky. You need a language with an easy handling,
well documented, with a large community of users. Python has all these qualities and more. It is modern,
powerful and widely used, including by professional programmers.
Despite all these qualities, starting programming (with Python or another language) is difficult. The best
thing is to already have experience with the code, using Scratch for example. There is still a big walk to
climb and this book is there to accompany you.
Objective
Mastering Python will allow you to easily learn other languages. Especially the language is not the most
important, the most important thing is the algorithms. Algorithms are like cooking recipes, you have to
follow the instructions step by step and what counts is the final result and not the language with which the
recipe was written. This book is therefore neither a complete Python manual nor a computer course, nor is
it about using Python as a super-calculator.
The aim is to discover algorithms, to learn step-by-step programming through mathematical/computer
activities. This will allow you to put mathematics into practice with the willingness to limit yourself to the
knowledge acquired during the first years.
Mathematics for computer science
Computer science for mathematics
Since computers only handle numbers, mathematics is essential to communicate with them. Another
example is the graphical on-screen display that requires a good understanding of the coordinates (
x,y
),
trigonometry....
Computers are a perfect match for mathematics! The computer becomes essential to manipulate very large
numbers or to test conjecture on many cases. In this book you will discover fractals, L-systems, brownian
trees and the beauty of complex mathematical phenomena.
You can retrieve all the activity codes and all the source files on the Exo7 GitHub page:
GitHub: Python in high school
Contents
I Getting started 1
1 Hello world! 2
2 Turtle (Scratch with Python) 9
II Basics 17
3 If ... then ... 18
4 Functions 24
5 Arithmetic – While loop – I 33
6 Strings – Analysis of a text 40
7 Lists I 50
III Advanced concepts 58
8 Statistics – Data visualization 59
9 Files 68
10 Arithmetic – While loop – II 77
11 Binary I 82
12 Lists II 89
13 Binary II 95
IV Projects 98
14 Probabilities – Parrondo’s paradox 99
15 Find and replace 102
16 Polish calculator – Stacks 107
17 Text viewer – Markdown 119
18 L-systems 126
19 Dynamic images 134
20 Game of life 140
21 Ramsey graphs and combinatorics 146
22 Bitcoin 155
23 Random blocks 164
V Guides 171
24 Python survival guide 172
25 Main functions 181
26 Notes and references 197
Index
Summary of the activities
Hello world!
Get into programming! In this very first activity, you will learn to manipulate numbers, variables and code your
first loops with .
Turtle (Scratch with Python)
The module allows you to easily make drawings in . It’s about ordering a turtle with simple
instructions like “go ahead”, “turn”... It’s the same principle as with Scratch, but with one difference: you no
longer move blocks, but you write the instructions.
If ... then ...
The computer can react according to a situation. If a condition is met, it acts in a certain way, otherwise it does
something else.
Functions
Writing a function is the easiest way to group code for a particular task, in order to execute it once or several
times later.
Arithmetic – While loop – I
The activities in this sheet focus on arithmetic: Euclidean division, prime numbers .. . This is an opportunity to
use the loop “while” intensively.
Strings – Analysis of a text
You’re going to do some fun activities by manipulating strings and characters.
Lists I
A list is a way to group elements into a single object. After defining a list, you can retrieve each item of the list
one by one, but also add new ones.. .
Statistics – Data visualization
It’s good to know how to calculate the minimum, maximum, average and quartiles of a series. It’s even better to
visualize them all on the same graph!
Files
You will learn to read and write data with files.
Arithmetic – While loop – II
Our study of numbers is further developed with the loop “while”. For this chapter you need your function
built in the part “Arithmetic – While loop – I”.
Binary I
The computers transform all data into numbers and manipulate only those numbers. These numbers are stored
in the form of lists of 0’s and 1’s. It’s the binary numeral system of numbers. To better understand this binary
numeral system, you will first understand the decimal numeral system better.
Lists II
The lists are so useful that you have to know how to handle them in a simple and efficient way. That’s the
purpose of this chapter!
Binary II
We continue our exploration of the world of 0 and 1.
Probabilities – Parrondo’s paradox
You will program two simple games. When you play these games, you are more likely to lose than to win.
However, when you play both games at the same time, you have a better chance of winning than losing! It’s a
paradoxical situation.
Find and replace
Finding and replacing are two very frequent tasks. Knowing how to use them and how they work will help you
to be more effective.
1 / 213 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !