background preloader

46 Simple Python Exercises

46 Simple Python Exercises
This is version 0.45 of a collection of simple Python exercises constructed (but in many cases only found and collected) by Torbjörn Lager (torbjorn.lager@ling.gu.se). Most of them involve characters, words and phrases, rather than numbers, and are therefore suitable for students interested in language rather than math. Very simple exercises Higher order functions and list comprehensions Simple exercises including I/O Somewhat harder exercises A sentence splitter is a program capable of splitting a text into sentences. Related:  Python

ISN à Notre Dame de Sion Evry 7 lines of code, 3 minutes: Implement a programming language A small (yet Turing-equivalent) language The easiest programming language to implement is a minimalist, higher-order functional programming language known as the lambda calculus. The lambda calculus actually lives at the core of all the major functional languages--Haskell, Scheme and ML--but it also lives inside JavaScript, Python and Ruby. It's even hiding inside Java, if you know where to find it. A brief history Alonzo Church developed the lambda calculus in 1929. Back then, it wasn't called a programming language because there were no computers; there wasn't anything to "program." It was really just a mathematical notation for reasoning about functions. Fortunately, Alonzo Church had a Ph.D. student named Alan Turing. Alan Turing defined the Turing machine, which became the first accepted definition of a general-purpose computer. What makes this remarkable is that there are only three kinds of expressions in the lambda calculus: variable references, anonymous functions and function calls.

Online Python exercises I've been thinking about online Python learners. There have been some cool examples of online code exercises, like Nathan's Javascript Lessons. These are great because they require absolutely no setup, and can run right on the web page that describes the concepts involved. But of course, it's easy to run Javascript in a browser. CodingBat provides exercises for Java and Python. Another server-side solution is the NCSS Challenge, which uses an elaborate sandboxing technique on the server to run arbitrary Python code. There are other server-side online Python execution pages: Server-side execution solve the problem of executing Python, but introduces the new problem of keeping the server safe. Try Python is an in-browser Python implementation using IronPython running in Silverlight. Reviewing all these possibilities, none are perfect, and some are far from it. Are there other possibilities?

Cours de programmation en langage Python - Spécialité ISN - Terminale S En 1989, le hollandais Guido van Rossum commence le développement du langage de programmation Python. Python est un langage multiplateforme, c'est-à-dire disponible sur plusieurs architectures (compatible PC, tablettes, smartphones, ordinateur low cost Raspberry Pi...) et systèmes d'exploitation (Windows, Linux, Mac, Android...). Le langage Python est gratuit, sous licence libre. C'est un des langages informatiques les plus populaires avec C, C++, C#, Objective-C, Java, PHP, JavaScript, Delphi, Visual Basic, Ruby et Perl (liste non exhaustive). Actuellement, Python en est à sa version 3. Cependant, la version 2 est encore majoritairement utilisée. Que peut-on faire avec Python ? Beaucoup de choses ! Des dizaines de milliers de librairies sont disponibles sur le dépôt officiel PyPI. Installation Sous Windows Une fois installé, vous pouvez lancer IDLE en allant dans : Démarrer → Programmes → Python → IDLE (Python GUI) Sous Linux Python est pré-installé sur la plupart des distributions Linux. Scripts

Five mini programming projects for the Python beginner After Shelly wrote this post, Webucator, a company that provides Python training, volunteered to create solutions for these projects. They've made a series of videos that'll help you out if you need it. Learning a new programming language is both the most exciting and the most humbling experience. For me, that language has recently been Python, which I’ve been learning over these last few months. With that in mind, here are five mini programming projects to get you started on learning Python. 1. The Goal: Like the title suggests, this project involves writing a program that simulates rolling dice. Concepts to keep in mind: RandomIntegerPrintWhile Loops A good project for beginners, this project will help establish a solid foundation for basic concepts. 2. The Goal: Similar to the first project, this project also uses the random module in Python. 3. The Goal: Inspired by Summer Son’s Mad Libs project with Javascript. 4. The Goal: Remember Adventure? 5.

Python Exercises Why Turing/Java/Python in grade 11? The choice of language for grade 11 is something I assume most schools take fairly seriously. I've been teaching 13 years and every year I review my choice of languages and ask myself if they are the best choices. I assume I'm not alone in this. Despite what you might think or hear around here I believe Turing is still a solid language in grade 11. I think most schools that teach Java in grade 11 do so because they want to use the same language for gr 11 and 12 so they can get past talking about syntax and focus on key concepts. I don't know of any other schools teaching Python in grade 11, but I wouldn't be shocked to find one. Please don't annoy/harass your teachers about their choice of programming languages, but a long as you approach them from a point of view of genuinely wanting to know why they teach language X, and have they considered language Y most teachers will be very honest with you.

Writing a game in Python with Pygame. Part I Introduction Games are one of the most applicative areas of programming. To write even the simplest games, you have to get into graphics, math, physics and even AI. It’s a great and fun way to practice programming. If you’re a fan of Python (and even if you aren’t) and are interested in games, Pygame is a great library for game programming, and you should definitely check it out. There are quite a lot of Pygame tutorials on the web, but most of them are basic. This tutorial explicitly encourages you to tinker with the code. Preliminaries For reasons I’ve mentioned above, this tutorial is not for complete beginners. Here, I assume that you have the following knowledge: Python (you don’t have to be an advanced user, but not a complete beginner either)Basics of math and physics (vectors, rectangles, laws of movement, probability, etc.). Let’s get started While this is not yet a game per se, it’s a useful starting point, from which we can implement many various ideas. The code Pygame’s docs

Design Patterns In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Uses of Design Patterns Design patterns can speed up the development process by providing tested, proven development paradigms. Often, people only understand how to apply certain software design techniques to certain problems. In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Creational design patterns These design patterns are all about class instantiation. Structural design patterns These design patterns are all about Class and Object composition. Private Class Data Restricts accessor/mutator access Proxy An object representing another object Behavioral design patterns Criticism Targets the wrong problem

Online Python Tutor Write your Python code here: x = [1, 2, 3] y = [4, 5, 6] z = y y = x x = z x = [1, 2, 3] # a different [1, 2, 3] list! x.append(4) y.append(5) z = [1, 2, 3, 4, 5] # a different list! x.append(6) y.append(7) y = "hello" def foo(lst): lst.append("hello") bar(lst) def bar(myLst): print(myLst) foo(x) foo(z) [Optional] Please answer these questions to support our research and to help improve this tool. Options: Execute code using , , , , , and . Here are some example Python code snippets to visualize: Basic: hello | happy | intro | filter | tokenize | insertion sort Math: factorial | fibonacci | memoized fibonacci | square root | gcd | towers of hanoi User Input: raw input Objects: OOP 1 | OOP 2 | OOP 3 | inheritance Linked Lists: LL 1 | LL 2 | LL sum Pointer Aliasing:aliasing 1 | aliasing 2 | aliasing 3 | aliasing 4aliasing 5 | aliasing 6 | aliasing 7 | aliasing 8 | sumList Higher-Order Functions: closure 1 | closure 2 | closure 3 | closure 4 | closure 5list map | summation | lambda param | student torture

Related: