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

From Hackerspace.gr
Jump to: navigation, search
m (removed mentions of the doodle link, added some text :)
 
Line 44: Line 44:
  
  
 +
exercise 05
 +
<pre>
 +
#!/usr/bin/python2
  
 +
name = 'Zed A. Shaw'
 +
age = 35 #not a lie
 +
height = 74 #inches
 +
weight = 180 #lbs
 +
eyes = 'Blue'
 +
teeth = 'White'
 +
hair = 'Brown'
  
 +
print "Let's talk about %s." % name
 +
print "He's %d centimeter tall." % ( height * 2.54)
 +
print "He's %f kg heavy." % (weight / 2.20)
 +
print "Actually that's not too heay."
 +
print "He's got %s eyes and %s hair." %(eyes, hair)
 +
print "His teeth are usually %s depending on the coffee. " % teeth
  
 +
# this line is tricky, try to get it exactly right
 +
print "If I add %d, %d, and %f I get %r." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20),2) )
 +
print "If I add %d, %f, and %f I get %f ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20),2) )
 +
print "If I add %d, %f, and %f I get %d ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20),2) )
 +
print "If I add %d, %f, and %f I get %d ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20) ) )
 +
print "If I add %d, %f, and %f I get %3.3f ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20) ) )
 +
print "If I add %d, %f, and %f I get %3.3f ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20) ,2 ) )
  
 +
</pre>
 +
 +
 +
exercise 06:
 +
 +
<pre>
 +
 +
# variable x
 +
x = "There are %d types of people. " % 10
 +
 +
# variable binary
 +
binary = "binary"
 +
 +
# variable do_not
 +
do_not = "don't"
 +
 +
# variable y
 +
y = "Those who know %s and those who %s." %(binary, do_not)
 +
 +
# print x
 +
print x
 +
# print y
 +
print y
 +
 +
# print repr, variable x
 +
# representation of string is in single quotes
 +
print "I said: %r." %x
 +
 +
# print repr, variable y
 +
print "I also said: '%s'." %y
 +
 +
# variable hilarious
 +
hilarious = False
 +
hilarious = True
 +
 +
# variable joke_evaluation
 +
joke_evaluation = "Isn't that joke so funny?! %r"
 +
#                                            ^
 +
#                                            |
 +
# print variable joke_evaluation, ------------+ and in the place of %r, put variable hilarious
 +
print joke_evaluation % hilarious
 +
 +
# variable w
 +
w = "This is the left side of ..."
 +
# variable e
 +
e = "a string with a right side."
 +
 +
# print w + e
 +
print w + e
 +
 +
 +
</pre>
  
  

Latest revision as of 19:09, 2 June 2015

Learn python the hard way.jpg

external link
Starts Organizer
Tue 02 Jun 2015 18:00
Ends Event Owner
Tue 02 Jun 2015 20:00 User:Ebal
  • ΜΟΝΟ αυτό το μάθημα, θα γίνει στις 02.06.2015 ημέρα Τρίτη κι όχι Δευτέρα


  • Κάθε Δευτέρα, 18:00-20:00
  • Συναντήσεις για εκμάθηση προγραμματισμού σε python.

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

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





  • 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 :)


This is Lesson 01 (intro session)

These events are based on peer2peer education



exercise 05

#!/usr/bin/python2

name = 'Zed A. Shaw'
age = 35 #not a lie
height = 74 #inches
weight = 180 #lbs
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'

print "Let's talk about %s." % name
print "He's %d centimeter tall." % ( height * 2.54)
print "He's %f kg heavy." % (weight / 2.20)
print "Actually that's not too heay." 
print "He's got %s eyes and %s hair." %(eyes, hair)
print "His teeth are usually %s depending on the coffee. " % teeth

# this line is tricky, try to get it exactly right
print "If I add %d, %d, and %f I get %r." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20),2) )
print "If I add %d, %f, and %f I get %f ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20),2) )
print "If I add %d, %f, and %f I get %d ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20),2) )
print "If I add %d, %f, and %f I get %d ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20) ) )
print "If I add %d, %f, and %f I get %3.3f ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20) ) )
print "If I add %d, %f, and %f I get %3.3f ." %( age, (height*2.54),(weight/2.20),round (  age + (height*2.54) + (weight/2.20) ,2 ) )


exercise 06:


# variable x
x = "There are %d types of people. " % 10

# variable binary
binary = "binary"

# variable do_not
do_not = "don't"

# variable y
y = "Those who know %s and those who %s." %(binary, do_not)

# print x
print x 
# print y
print y

# print repr, variable x
# representation of string is in single quotes
print "I said: %r." %x 

# print repr, variable y
print "I also said: '%s'." %y

# variable hilarious
hilarious = False
hilarious = True

# variable joke_evaluation
joke_evaluation = "Isn't that joke so funny?! %r"
#                                             ^
#                                             |
# print variable joke_evaluation, ------------+ and in the place of %r, put variable hilarious
print joke_evaluation % hilarious 

# variable w
w = "This is the left side of ..."
# variable e
e = "a string with a right side."

# print w + e 
print w + e



Previous, on Learning Python the Hard Way:

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