You've learned Ruby, C, C++, JavaScript and SQL. Getting started with a totally new language doesn't have to be hard. The biggest key is to practice doing something that you already know in the context of the new language. This is called a transfer task. The more languages and computer science concepts you learn, the easier new ones become to pick up and its mostly syntax, quirks and language-specific tools that become the tricky part.
Now, your task is to teach yourself a bit of Python. The goal here isn't to become a Python master, but to explore and learn a bit about a new language.
All exercises below should be done with Python 3
By the end of this exercise, you should be able to:
- Create a simple python program
- Execute a simple python program
- Articulate basic differences between Python and other languages you know
- Feel comfortable understanding what is generally happening in most basic python programs
Your Mac comes with Python 2.7. We want Python 3.
brew install python3
Execute the Python REPL with:
python3
Execute a Python program with:
python3 program.py
Your first task is to research Python to be able to understand some of its basic concepts. Edit this README.md
file to answer the below questions:
The Zen of Python, by Tim Peters
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
Write a program in hello_world/hello_world.py
that prints 'Hello, World!' to the standard output (terminal).
Write a program in fizzbuzz/fizzbuzz.py
that does the following:
For numbers 1 through 100, print fizz
if the number is divisible by 3, buzz
if the number is divisible by 5 and fizzbuzz
if the number if the number is divisible by both 3 and 5. If the number isn't divisible by 3 or 5, just output the number itself.
The output should look something like 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 Fizz Buzz 16 17 Fizz...
Write a program in fibonacci/fib.py
that will output the N-th term of the Fibonacci sequence.
For example: print fib(6)
should output 8
.
Project Euler's first problem is:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
Write the code to complete this in euler_1/sum_of_natural_numbers.py
How does Python compare to other langauges you've used? Which language is is closest to?