Difference between revisions of "Learn Python the Hard Way 02"

From Hackerspace.gr
Jump to: navigation, search
 
(One intermediate revision by one other user not shown)
Line 19: Line 19:
  
  
 +
* Στις προηγούμενες συναντήσεις έχουμε καλύψει τις ασκήσεις 0 εως και 6
  
 +
 +
 +
Η σελίδα της προηγούμενης συνάντησης (01) με μερικές σημειώσεις: https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_01
  
 
----
 
----
Line 35: Line 39:
  
 
Come early if you want to ensure that you'll find a space to place your laptop :)
 
Come early if you want to ensure that you'll find a space to place your laptop :)
 +
 +
 +
* We have previously covered exercises 0 to 6 (including 6)
 +
 +
 +
The page for the previous meeting (01) with some notes: https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_01
 +
  
  
Line 42: Line 53:
  
  
Previous, on Learning Python the Hard Way:
+
exercise 7
 +
<pre>
 +
#!/usr/bin/env python2
 +
 
 +
print "Mary had a little lamb."
 +
print "Its fleece was white as %s." % 'snow'
 +
print "And everywhere that Mary went."
 +
print "." * 10 # what'd that do?
 +
 
 +
maria1  = "C"
 +
maria2  = "h"
 +
maria3  = "e"
 +
maria4  = "e"
 +
maria5  = "s"
 +
maria6  = "e"
 +
maria7  = "B"
 +
maria8  = "u"
 +
maria9  = "r"
 +
maria10 = "g"
 +
maria11 = "e"
 +
maria12 = "r"
 +
maria13 = "!"
 +
maria14 = "!"
 +
maria15 = "!"
 +
 
 +
# watch that comma at the maria. try removing it to see what happens
 +
print maria1 + maria2 + maria3 + maria4 + maria5 + maria6 + " " + maria7 + maria8 + maria9 + maria10 + maria11 + maria12 + maria13
 +
 
 +
print maria1 + maria2 + maria3 + maria4 + maria5 + maria6,
 +
print maria7 + maria8 + maria9 + maria10 + maria11 + maria12 + maria13 + maria14 + maria15
 +
 
 +
print maria1 + maria2 + maria3 + maria4 + maria5 + maria6, \
 +
maria7 + maria8 + maria9 + maria10 + maria11 + maria12 + maria13 + maria14 \
 +
+ maria15
 +
 
 +
 
 +
</pre>
 +
 
 +
exercise 8
 +
<pre>
 +
formatter  = "%r %r %r %r"
 +
formatter2 = "%s %s %s %s"
 +
 
 +
print formatter % (1, 2, 3, 4)
 +
print formatter % ("one", "two", "three", "four")
 +
print formatter % (True, False, False, True)
 +
print formatter % (formatter, formatter, formatter, formatter)
 +
print formatter % (
 +
    "I had this thing.",
 +
    "That you could type up right.",
 +
    "But it didn't sing.",
 +
    "So I said goodnight."
 +
)
 +
 
 +
print formatter2 % (1, 2, 3, 4)
 +
print formatter2 % ("one", "two", "three","four")
 +
print formatter2 % (True, False, False, True)
 +
print formatter2 % (formatter2, formatter2, formatter2, formatter2)
 +
print formatter2 % (
 +
    "I had this thing.",
 +
    "That you could type up right.",
 +
    "But it didn't sing.",
 +
    "So I said goodnight."
 +
)
 +
 
 +
</pre>
 +
 
 +
exercise 9
 +
<pre>
 +
 
 +
# Here's some new strage stuff, remember type it exactly.
 +
 
 +
days = "Mon Tue Wed Thu Fri Sat Sun"
 +
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
 +
 
 +
print "Here are the days: ", days
 +
print "Here are the months: ", months
 +
 
 +
print """
 +
There's something going on here.
 +
With the three double-quotes.
 +
We'll be able to type as much as we like.
 +
Even 4 lines if we want, or 5, or 6.
 +
"""
 +
 
 +
print """
 +
There's something going on here.
 +
With the three double-quotes.
 +
We'll be able to type as much as we like.
 +
Even 4 lines if we want, or 5, or 6.
 +
"""
 +
 
 +
 
 +
</pre>
 +
 
 +
exercise 10
 +
 
 +
<pre>
 +
 
 +
tabby_cat = "\tI'm tabbbed in."
 +
persian_cat = "I'm split\non a line."
 +
backslash_cat = "I'm \\ a \\ cat."
 +
 
 +
fat_cat = """
 +
I'll do a list:
 +
\t* Cat food
 +
\t* Fishies
 +
\t* Catnip\n\t* Grass
 +
"""
 +
 
 +
print tabby_cat
 +
print persian_cat
 +
print backslash_cat
 +
print fat_cat
 +
 
 +
fat_cat2 = '''
 +
I'll do a list:
 +
\t* Cat's food
 +
\t* "Fis"""hies"
 +
\t* Catnip\n\t* //Grass
 +
'''
 +
 
 +
 
 +
print fat_cat2
 +
 
 +
 
 +
 
 +
months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
 +
print months
 +
 
 +
 
 +
</pre>
  
https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_01
 
 
|eventowner=User:Ebal
 
|eventowner=User:Ebal
 
|url=http://learnpythonthehardway.org/book/
 
|url=http://learnpythonthehardway.org/book/

Latest revision as of 16:58, 10 June 2015

Learn python the hard way.jpg

external link
Starts Organizer
Mon 08 Jun 2015 18:00
Ends Event Owner
Mon 08 Jun 2015 20:00 User:Ebal
  • Κάθε Δευτέρα, 18:00-20:00
  • Συναντήσεις για εκμάθηση προγραμματισμού σε python.

Θα είναι υπό την μορφή study group, δηλαδή όλοι θα μαθαίνουμε παρέα και δεν θα υπάρχει κάποιος "δάσκαλος". Οι συναντήσεις είναι ανοιχτές σε όλες και όλους - αρκεί να φέρεις το laptop σου! Απευθύνονται σε ανθρώπους που θέλουν να ξεκινήσουν με python κι άρα θα είναι αρκετά εισαγωγικές. Η μοναδική δέσμευση είναι να τηρηθεί αυστηρά το ωράριο (δηλαδή εάν κάποιος ή κάποια αργήσει, να μην μας ζητήσει να γυρίσουμε πίσω για να καλύψουμε κάτι που έχουμε ήδη πει).

Έλα εγκαίρως/νωρίς αν θες να βρεις ελεύθερη θέση :)


  • Στις προηγούμενες συναντήσεις έχουμε καλύψει τις ασκήσεις 0 εως και 6


Η σελίδα της προηγούμενης συνάντησης (01) με μερικές σημειώσεις: https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_01



  • Every Monday at 18.00-20:00
  • python enthusiasts will try to learn programming "the hard way" !

The meetings will be in study group format, meaning that we will all learn together and there won't be a tutor. Meetings are open to everyone - just bring your laptop! They are for people that want to start learning python, so we will cover some introductory material. The only requirement is to be punctual (so if a person comes later than 18:00 please don't ask us to cover material that we have already gone through).

Come early if you want to ensure that you'll find a space to place your laptop :)


  • We have previously covered exercises 0 to 6 (including 6)


The page for the previous meeting (01) with some notes: https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_01


This is Lesson 02 (intro session)

These events are based on peer2peer education


exercise 7

#!/usr/bin/env python2

print "Mary had a little lamb."
print "Its fleece was white as %s." % 'snow'
print "And everywhere that Mary went."
print "." * 10 # what'd that do?

maria1  = "C"
maria2  = "h"
maria3  = "e"
maria4  = "e"
maria5  = "s"
maria6  = "e"
maria7  = "B"
maria8  = "u"
maria9  = "r"
maria10 = "g"
maria11 = "e"
maria12 = "r"
maria13 = "!"
maria14 = "!"
maria15 = "!"

# watch that comma at the maria. try removing it to see what happens
print maria1 + maria2 + maria3 + maria4 + maria5 + maria6 + " " + maria7 + maria8 + maria9 + maria10 + maria11 + maria12 + maria13

print maria1 + maria2 + maria3 + maria4 + maria5 + maria6,
print maria7 + maria8 + maria9 + maria10 + maria11 + maria12 + maria13 + maria14 + maria15

print maria1 + maria2 + maria3 + maria4 + maria5 + maria6, \
maria7 + maria8 + maria9 + maria10 + maria11 + maria12 + maria13 + maria14 \
 + maria15


exercise 8

formatter  = "%r %r %r %r"
formatter2 = "%s %s %s %s"

print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")
print formatter % (True, False, False, True)
print formatter % (formatter, formatter, formatter, formatter)
print formatter % (
    "I had this thing.",
    "That you could type up right.",
    "But it didn't sing.",
    "So I said goodnight."
)

print formatter2 % (1, 2, 3, 4)
print formatter2 % ("one", "two", "three","four")
print formatter2 % (True, False, False, True)
print formatter2 % (formatter2, formatter2, formatter2, formatter2)
print formatter2 % (
    "I had this thing.",
    "That you could type up right.",
    "But it didn't sing.",
    "So I said goodnight."
)

exercise 9


# Here's some new strage stuff, remember type it exactly.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"

print "Here are the days: ", days
print "Here are the months: ", months

print """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
"""

print """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
"""


exercise 10


tabby_cat = "\tI'm tabbbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\ a \\ cat."

fat_cat = """
I'll do a list:
\t* Cat food
\t* Fishies
\t* Catnip\n\t* Grass
"""

print tabby_cat
print persian_cat
print backslash_cat
print fat_cat

fat_cat2 = '''
I'll do a list:
\t* Cat's food
\t* "Fis"""hies"
\t* Catnip\n\t* //Grass
'''


print fat_cat2



months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
print months