Learn Python the Hard Way

From Hackerspace.gr
Jump to: navigation, search
Learn python the hard way.jpg

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

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

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


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

Exercise 17: More Files


Η σελίδα της προηγούμενης συνάντησης (6η) με μερικές σημειώσεις:

https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_06



  • 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 till 17 (including Exercise 17: More Files)


The page for the previous meeting (#06) with some notes:

https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_06

These events are based on peer2peer education


These notes are from Lesson 07

Exercise 18: Names, Variables, Code, Functions

#!/usr/bin/python2

# this one is like your scripts with argv
def print_two (*args):
    arg1, arg2 = args
    print "arg1: %r, arg2: %r" % (arg1, arg2)

# this one is like your scripts with argv
def print_two2 (*argument_list):
    print "arg1: %r, arg2: %r, arg3: %r" % ( argument_list[0], argument_list[1], argument_list[2] )
    print "arg4: %r" % argument_list[3]

# this one is like your scripts with argv
def print_22 (*argument_list):
    for i in argument_list:
        print "argument: %r " % i

# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
    print "arg1: %r, arg2: %r" % (arg1, arg2)

# this kust takes one argument
def print_one(arg1):
    print "arg1: %r" % arg1

# this one takes no arguments
def print_none():
    print "I got nothin'."
    print "test"

# this one takes no arguments
def print_n0n3( *argsss ):
    print "n0n3: I got nothin'."


# this one takes no arguments
def print_n0ne( arg1 ):
    print "n0ne: I got nothin'."

print_two("Zed","Shaw")
print_two2("ebal", "ebal2", "ebal3", "ebal4")
print_n0n3( )
print_two_again("Zed", "Shaw")
print_one("First!")
print_none()
print_22("ebal1","ebal2","ebal3","ebal4","ebal5")
print_none ( "test" )
print_n0ne( )

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

Exercise 19: Functions and Variables

#!/usr/bin/env python2

# define a new function with name: cheese_and_crackers
# We pass two arguments inside this function

cheese_count = 25 
boxes_of_crackers = 35 

# def cheese_and_crackers ( cheese_count , boxes_of_crackers ):
# initiliaze function variables cheese_count and boxes_of_crackers with default values
def     cheese_and_crackers       (      cheese_count     =       15        ,     boxes_of_crackers = 15 ):
    """ This is a doc string, the help of this function """
    print "You have %d cheeses!" % cheese_count
    print "You have %d boxes of crackers!" % boxes_of_crackers
    print aaa ( cheese_count ) 

def aaa ( bbb ):
    return bbb*10

print "We can just give the function numbers directly:"
cheese_and_crackers ( 20 , 30 )

print "OR, we can use variables from our script:"
amount_of_cheese   = 10
amount_of_crackers = 50

cheese_and_crackers ( amount_of_cheese, amount_of_crackers )

print "We can even do math inside too:"
cheese_and_crackers ( 10 + 20,  5 + 6 )

print "And we can combine the two, variables and math:"
cheese_and_crackers ( amount_of_cheese + 100, amount_of_crackers + 1000 )

print "Cheese and crackers " 
cheese_and_crackers ( cheese_count ,  boxes_of_crackers  )

print "Cheese and crackers " 
cheese_and_crackers ( )


print "Cheese and crackers " 
cheese_and_crackers(int(raw_input("cheese? ")), int(raw_input("crackers? "))) 

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

"""
1.
cheese_count = 20
boxes_of_crackers 30

2.
cheese_count = amount_of_crackers = 10
boxes_of_crackers = amount_of_crackers = 50

3.
cheese_count = 10 + 20 = 30
boxes_of_crackers = 5 + 6 = 11 

4.
cheese_count = amount_of_cheese + 100 = 10 + 100 = 110
boxes_of_crackers = amount_of_boxes + 1000 = 50 + 1000 = 1050

5.
cheese+count = 25
boxes_of_crackers = 35 
"""