Skip to content

Commit

Permalink
Finished slide #3 control structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Elfanbaum committed Oct 9, 2015
1 parent 1e370f0 commit b33d77f
Show file tree
Hide file tree
Showing 11 changed files with 549 additions and 65 deletions.
4 changes: 2 additions & 2 deletions notebooks/modules-and-packages.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 3.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -116,4 +116,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
15 changes: 14 additions & 1 deletion slides/1-introduction.html → slides/01-introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<div class="reveal">
<div class="slides">
<section data-markdown="content/1-introduction.md" data-separator="^---" data-separator-vertical="^--"
<section data-markdown="content/01-introduction.md" data-separator="^---" data-separator-vertical="^--"
data-separator-notes="^Note:" data-charset="iso-8859-15">
</section>
</div>
Expand Down Expand Up @@ -115,6 +115,19 @@
background: #3F3F3F;
}

.reveal li pre {
width: 100%;
}

.reveal h6 {
color: #558D85;
font-weight: 300;
text-align: right;
}




</style>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<div class="reveal">
<div class="slides">
<section data-markdown="content/2-variables-and-data-types.md" data-separator="^---" data-separator-vertical="^--"
<section data-markdown="content/02-variables-and-data-types.md" data-separator="^---" data-separator-vertical="^--"
data-separator-notes="^Note:" data-charset="iso-8859-15">
</section>
</div>
Expand Down Expand Up @@ -115,6 +115,19 @@
background: #3F3F3F;
}

.reveal li pre {
width: 100%;
}

.reveal h6 {
color: #558D85;
font-weight: 300;
text-align: right;
}




</style>

<script>
Expand Down
139 changes: 139 additions & 0 deletions slides/03-control-structures.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">

<title>Pycubator|Control structures</title>

<meta name="author" content="Noam Elfanbaum">

<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>

<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">

<link rel="stylesheet" href="revealjs/css/reveal.css">
<link rel="stylesheet" href="revealjs/css/theme/black.css" id="theme">
<!-- <link rel="stylesheet" href="css/my.css">-->

<!-- Code syntax highlighting -->
<link rel="stylesheet" href="revealjs/lib/css/zenburn.css">

<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'revealjs/css/print/pdf.css' : 'revealjs/css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>

<!--[if lt IE 9]>
<script src="revealjs/lib/js/html5shiv.js"></script>
<![endif]-->
</head>

<body>

<div class="reveal">
<div class="slides">
<section data-markdown="content/03-control-structures.md" data-separator="^---" data-separator-vertical="^--"
data-separator-notes="^Note:" data-charset="iso-8859-15">
</section>
</div>
</div>
<script src="revealjs/lib/js/head.min.js"></script>
<script src="revealjs/js/reveal.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,

transition: 'slide', // none/fade/slide/convex/concave/zoom

// Optional reveal.js plugins
dependencies: [{
src: 'revealjs/lib/js/classList.js',
condition: function () {
return !document.body.classList;
}
}, {
src: 'revealjs/plugin/markdown/marked.js',
condition: function () {
return !!document.querySelector('[data-markdown]');
}
}, {
src: 'revealjs/plugin/markdown/markdown.js',
condition: function () {
return !!document.querySelector('[data-markdown]');
}
}, {
src: 'revealjs/plugin/highlight/highlight.js',
async: true,
condition: function () {
return true;
},
callback: function () {
hljs.initHighlightingOnLoad();
}
}, {
src: 'revealjs/plugin/zoom-js/zoom.js',
async: true
}, {
src: 'revealjs/plugin/notes/notes.js',
async: true
}]
});
</script>
<div class="back-to-index"
style="display: none; position: absolute; top: 16px; left: 10px; z-index: 20;">
<a href="index.html">Back to index</a>
</div>

<style scoped>
.back-to-index a {
display: inline-block;
height: 34px;
line-height: 34px;
padding: 0 10px;
color: #fff;
font-family: Helvetica, serif;
text-decoration: none;
font-size: 12px;
vertical-align: top;
text-transform: uppercase;
box-sizing: border-box;
border: 1px solid #fff;
}

.reveal code {
font-size: 90%;
background: #3F3F3F;
}

.reveal li pre {
width: 100%;
}

.reveal h6 {
color: #558D85;
font-weight: 300;
text-align: right;
}




</style>

<script>
if (!navigator.userAgent.match(/(iphone|android)/gi) && !!document.querySelector) {
document.querySelector('.back-to-index').style.display = 'block';
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

---

# Py...what?
<!-- .slide: data-background="img/puzzles.jpg" -->

--

### About

* Guido Van-Rossum side project in the late 1980's
Expand Down Expand Up @@ -134,6 +129,21 @@
$ python /tmp/example.py
hello world!

--
### IDE - PyCharm

[PyCharm](https://www.jetbrains.com/pycharm/) is a great python IDE.
A commercial and a community versions are available for download.

Here are some tips for PyCharm:

- You can set up both python 2 and python 3 side by side.
- Use `Alt+Enter` for quick fixes, including *auto import* (which is very useful).
- Use `Ctrl+Shift+A` to find any command or setting!
- Use `Ctrl+Alt+L` to reformat your code.
- Use `Ctrl+Shift+F10` to run the current file.
- Use `Shift+F10` to run again the last file.
- Use `Ctrl+Space` for method/variable autocomplete.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ And what about `not 3`?
The following string literals are equivalent:

"Hello World!"
'Hello World!"
'Hello World!'
"""Hello World!"""
'''Hello World!'''

Expand Down Expand Up @@ -204,19 +204,19 @@ in Python docs for more information.

To disable escape sequences, raw string literals can be used:

>>> print "c:\windows\newstuff\todo" # OOPS!
>>> print('c:\windows\newstuff\todo') # OOPS!
c:\windows
ewstuff odo
>>> print r"c:\windows\newstuff\todo" # Better.
>>> print(r'c:\windows\newstuff\todo') # Better.
c:\windows\newstuff\todo

--

Sadly, raw string literals cannot end with a backslash:

>>> print r"c:\work\"
>>> print(r'c:\work\')
SyntaxError:...
>>> print r"c:\work" + "\\" # workaround.
>>> print(r'c:\work' + '\\') # workaround.
c:\work\

---
Expand Down Expand Up @@ -271,7 +271,6 @@ All the methods bellow return new string (there is no in place operations!).

'hello, and ,welcome'.split(',', maxsplit=1) # -> ['hello', ' and ,welcome']


* splitlines - splits and leaves the `\n` out

'''hi
Expand All @@ -287,4 +286,72 @@ All the methods bellow return new string (there is no in place operations!).

* strip, rstrip, lstrip - removes spaces and new lines from the ends of a string:

" hello! \n".strip() # -> "hello!"
' hello! \n'.strip() # -> 'hello!'

---

# String formatting

--
### Basic formating

# getting user input
name = input() # python3
name = raw_input() # python2

# old style formatting
print('Hello %s!' % name)

# new style formatting
print('Hello {}!'.format(name))

--
### More formating
- Named formatting

>>> '{name} {age}'.format(age=5, name='Mike')
mike 5

- `{:4}{:7}` at least x number of chars
- `{:b}{:x}` formats number as binary or hex
- in short,`{name!conversion:format}` provides options on top of `{}`

--
### Resources
- [Format Specification Mini-Language](https://docs.python.org/2/library/string.html#format-specification-mini-language).
- [Examples](https://docs.python.org/2/library/string.html#format-examples)
- [String Formatting Cookbook](http://ebeab.com/2012/10/10/python-string-format/)
- [Common use cases](http://pyformat.info/)


--
###### Excercise 1

Complete the following code:

name = 'joe'
sons = 2
daughters = 3

# ----- ENTER YOUR CODE HERE --------
s = ''
# -----------------------------------

print(s)
assert s == 'Joe has 5 kids.'

--
###### Excercise 2

Use the code from the previous exercise to write a short program that asks
the user for input and prints the answer as following:

What is the parent name?
> joe
How many sons does he have?
> 2
How many daughters does he have?
> 3
Joe has 5 kids.


Loading

0 comments on commit b33d77f

Please sign in to comment.