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.

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?

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.

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. Behavioral design patterns These design patterns are all about Class's objects communication. Criticism Targets the wrong problem Lacks formal foundations

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

A Beginner's Guide to Design Patterns Ever wondered what design patterns are? In this article, I'll explain why design patterns are important, and will provide some examples, in PHP, of when and why they should be used. Design patterns are optimized, reusable solutions to the programming problems that we encounter every day. There are three basic kinds of design patterns: structural creationalbehavioral Structural patterns generally deal with relationships between entities, making it easier for these entities to work together. Creational patterns provide instantiation mechanisms, making it easier to create objects in a way that suits the situation. Behavioral patterns are used in communications between entities and make it easier and more flexible for these entities to communicate. Design patterns are, by principle, well-thought out solutions to programming problems. Let's imagine that you've been given the responsibility of creating a way to merge two classes which do two different things based on the situation.

Design Patterns | Object Oriented Design Programming paradigm High-level computer programming conceptualization A programming paradigm is a relatively high-level way to structure and conceptualize the implementation of a computer program. A programming language can be classified as supporting one or more paradigms.[1] Some common programming paradigms include (shown in hierarchical relationship):[2][3][4] Overview[edit] Programming paradigms come from computer science research into existing practices of software development. When using a language that supports multiple paradigms, the developer chooses which paradigm elements to use. Languages categorized as imperative paradigm have two main features: they state the order in which operations occur, with constructs that explicitly control that order, and they allow side effects, in which state can be modified at one point in time, within one unit of code, and then later read at a different point in time inside a different unit of code. Criticism[edit] History[edit] Languages and paradigms[edit]

Related: