Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 217 T03 Week I Part #2: Python Tricks for Exercise #1 Hubert (Sathaporn) Hu.

Similar presentations


Presentation on theme: "CPSC 217 T03 Week I Part #2: Python Tricks for Exercise #1 Hubert (Sathaporn) Hu."— Presentation transcript:

1 CPSC 217 T03 Week I Part #2: Python Tricks for Exercise #1 Hubert (Sathaporn) Hu

2 About Me, Redux My name is Hubert (Sathaporn) Hu.  You should only call me Sathaporn if you know Thai… Otherwise, call me Hubert. My email address is: sathaporn.hu@ucalgary.ca sathaporn.hu@ucalgary.ca  Please put CPSC217 in email’s subject I also have website: http://husathap.github.io.http://husathap.github.io  The course material is also available here!

3 Today’s Tutorial I’ll be much more hand-off than the previous class… It will mostly used for Exercise #1. However, I saw that most of you don’t have a good coding style. I’ll go over that first. I’ll go over some hacks that can make your life easier.

4 TIPS! 1.Comments do not influence your code in anyway. For instance, if you put this comment anywhere in your code: # They see me rolling, they hating! Your program won’t behave any differently. 2.Some code is prettier than the other. 3.You get free Microsoft Office and also free OneDrive storage by being UCalgary student!

5 Stylish Code! This code is ugly. Can you make it prettier? (I’ve noticed this style from a couple people who did Exercise #1 in the last class.) memetext=‘2fast4u’ animal=‘jackrabbit’ verb=‘is’ print(animal,verb,memetext)

6 Stylish Code! Code is like airlines passengers; it likes to have spaces and pretty of legroom! Also, use _ when naming a variable! animal = ‘jackrabbit’ verb = ‘is’ meme_text = ‘2fast4u’ print(animal, verb, meme_text)

7 String Formatting Sometimes, concatenating strings can be cumbersome: num_meme = 400 meme_type = ‘dank’ meme_type_2 = ‘skeleton’ print(“The dootiest memes are “ + \ str(num_meme) + meme_type + meme_type_2 + \ “ memes!”) OUTPUT: The dootiest memes are 400 dank skeleton memes!

8 String Formatting I give you String Formatting! subject = ‘Math’ predicate = ‘difficult’ print(“{} is {}.”.format(subject, predicate)) OUTPUT: Math is difficult. A more complicated version will show up later on in lecture. Hmm... I wonder where I could use this…

9 Exercise #1 EXERCISE: Complete Exercise #1 DANGER: This code can be completed in one line, but just because it can be done, doesn’t mean it should be. HINT: You don’t need that many lines.


Download ppt "CPSC 217 T03 Week I Part #2: Python Tricks for Exercise #1 Hubert (Sathaporn) Hu."

Similar presentations


Ads by Google