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

From Hackerspace.gr
Jump to: navigation, search
 
Line 56: Line 56:
  
 
''These notes are from Lesson 09''
 
''These notes are from Lesson 09''
 +
 +
'''Exercise 24: More Practice'''
  
 
<pre>
 
<pre>
 +
#!/usr/bin/python2
 +
 +
print0 = "Let's practice everything."
 +
print print0
 +
 +
print1 = 'You \'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
 +
print print1
 +
 +
poem = """
 +
\tThe lovely world
 +
with logiv so firmly planted
 +
cannot discern \n the needs of love
 +
nor comprehend passion from intuition
 +
and requires an exaplantion
 +
\n\t\twhere there is none.
 +
"""
 +
 +
print2 = "--------------"
 +
print print2
 +
print poem
 +
print print2
 +
 +
five = ( ( 10 - 2 )  + ( 3 - 6 ) )
 +
 +
print "This should be five: %s" % five
 +
print "This should be five: %d" % five
 +
print "This should be five: %r" % five
 +
 +
# define function with name: secret_formula
 +
# takes one argument with name: started
 +
def secret_formula ( started ):
 +
# PLZ dont DO IT, dont declare global variables
 +
# global ebal
 +
jelly_beans = started * 500
 +
jars = jelly_beans / 1000
 +
crates = jars / 100
 +
return jelly_beans, jars, crates, 2000*1000
 +
 +
start_point = 10000
 +
beans, jars, crates, ebal = secret_formula ( start_point )
 +
 +
print ""
 +
print "ebal: " + str ( ebal )
 +
print "ebal: %d " %  ebal
 +
print "ebal: %s " % ebal
 +
print "ebal:", ebal
 +
print ""
 +
 +
print "With a starting point of: %d" % start_point
 +
print "We 'd have %d beans, %d jars, and %d crates." % ( beans, jars, crates )
 +
 +
start_point = start_point / 10
 +
 +
print "We can also do that this way:"
 +
print "We 'd have %d beans, %d jars, and %d crates. %d " % secret_formula ( start_point )
 +
 
</pre>
 
</pre>
  

Latest revision as of 19:20, 27 July 2015

Learn python the hard way.jpg

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

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

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


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

Exercise 21: Functions Can Return Something


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

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



  • 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 21 (including Exercise 21: Functions Can Return Something )


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

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

These events are based on peer2peer education


These notes are from Lesson 09

Exercise 24: More Practice

#!/usr/bin/python2

print0 = "Let's practice everything."
print print0

print1 = 'You \'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
print print1

poem = """
\tThe lovely world
with logiv so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an exaplantion
\n\t\twhere there is none.
"""

print2 = "--------------"
print print2
print poem 
print print2

five = ( ( 10 - 2 )  + ( 3 - 6 ) )

print "This should be five: %s" % five
print "This should be five: %d" % five
print "This should be five: %r" % five

# define function with name: secret_formula
# takes one argument with name: started 
def secret_formula ( started ):
	# PLZ dont DO IT, dont declare global variables
	# global ebal
	jelly_beans = started * 500
	jars = jelly_beans / 1000
	crates = jars / 100
	return jelly_beans, jars, crates, 2000*1000

start_point = 10000
beans, jars, crates, ebal = secret_formula ( start_point ) 

print ""
print "ebal: " + str ( ebal )
print "ebal: %d " %  ebal 
print "ebal: %s " % ebal
print "ebal:", ebal
print ""

print "With a starting point of: %d" % start_point
print "We 'd have %d beans, %d jars, and %d crates." % ( beans, jars, crates )

start_point = start_point / 10 

print "We can also do that this way:"
print "We 'd have %d beans, %d jars, and %d crates. %d " % secret_formula ( start_point )