Posts

*Hiatus* - for the time being

This is for good reasons! I'm having a little break from Python as I'm focusing specifically on Power BI - a data analysis programme that links to both my work - and to this, in a way.  I'm not abandoning Python though. I'm going to do another entry this week, just so that I can keep that going and build up the learning gradually. Once I've completed this course (eventually!) I'll then consider next steps for future courses, or just to leave it there.  I need to see how the Power BI thing works first. Just to update to make it clear I just haven't bothered! 

Introduction to Python Programming Course - Part 14

Final bit of consolidation. The rest of Control Flow. Last time I really got to grips with creating a new list from existing and modifying one. The extra practice is worth it - need to ensure I do the same here and not just rush through! Start Time - 16:44 So Udacity is not working! I've tried various times and it simply won't open. So I'm not going to give up and have hunted around for some other Control Flow stuff. Going to go over this for around half an hour, then hope Udacity is working tomorrow. If not, time for a new course! https://pynative.com/python-control-flow-statements/ For loops These are iterated a fixed number of times. You need to know that number of times. For an unknown number, use while loops. Also good for when doing something with values in a list. Challenge - I overcomplicated by doing the % 2 == 0 - in range, I can just do a step of 2! Break statement - this terminates the loop. Then it goes onto the next line of code. Or the innermost loop in neste...

Introduction to Python Programming Course - Part 13

 More consolidation time! Control flow here we go... Start Time - 19:48 Conditional Statements If - this uses colon. Checks a condition. Elif - instead of else if. Else - all others.  It skips code if a condition is not true.  Indentation - this is more than a visual. It determines what lines of code are then run. *SOmething I've noticed is that it's better to put a whole string, then use the format method, than it is to add individual Int or other values. Makes more sense and easier.  Boolean Expression Next bit now. All good so far.  This could be using and, or, not. Or more complex expressions. Never use 'true' or 'false'. If statement always evaluated to true - no point! 'Not' operator to see if something is false.  Use 'None' for an no value. Not 'nil' like that is in Swift.  This is how you use a range of values: elif 151 <= points <= 180: Elif could be if or else (irrelevant). But we have the number, the comparison, then the ...

Introduction to Python Programming Course - Part 12

More consolidation needed! I went over section 1 (Data Types and Operations) now need to do the same with structures, so all of that is clear. THEN go through control flow again. After that, I'll try those end of unit challenges. If I still can't get them, then it's fine - it's just to make sure I've got everything clear up to that point! Data Structures Lists These are essentially arrays from Swift. Same in syntax and use of certain methods e.g. append and += to add an element.  This is a container of data. Lists are ordered. Using the index - starting from 0. All that is fine. -1 of the index would be the last element of the list. Lists can also be of multiple types e.g. you can use an Int, a string etc.  Slicing in lists - this is using a colon in the index part. E.g. [:3]. That would go up to the fourth index but essentially have the first three items. *Need to try out this with examples! OK I've done some more practice! :2 would be the first two. Or the ite...

Introduction to Python Programming Course - Part 11

 Time to finish control flow! Once I have, I will spend some time consolidating this whole section. Lots of syntax and logic just to make proper sense of - not like it needs to be memorised, but I need to get how to adapt the right code to the right purpose! Start Time - 11:38 List Comprehensions So this is using a for loop in one step to create a list. The syntax is v similar to first line of for loop without colon. Don't need a new list beforehand. Like a for loop would do.  List comprehension is more concise than the actual for loop. Conditionals can be added - an if statement to refine what goes in even more. NO ELSE can be added. You have to move the conditionals to the start of the list comprehension. Also LC are not in other languages - just python. OK so far! The quiz was tough -  names = ["Rick Sanchez", "Morty Smith", "Summer Smith", "Jerry Smith", "Beth Smith"] first_names = [name.split()[0].lower() for name in names] # w...

Introduction to Python Programming Course - Part 10

Just managing to squeeze in a weekday session. Am on holiday from work so time on a Friday! More on control flow. Lots on different for and while loops - will need to keep working on these and using in context as they're conceptually tricky. Start Time - 10:17 Break, Continue For more precise loop of when 'Break' is used. Used to end the loop if we detect a condition has been met. Used in for and while.  Cargo weight example - if over a weight, break statement means we stop loading. Continue - skips just one iteration.  Challenge - this was tricky! I nearly had it -  # HINT: modify the headlines list to verify your loop works with different inputs headlines = ["Local Bear Eaten by Man",              "Legislature Announces New Laws",              "Peasant Discovers Violence Inherent in System",              "Cat Rescues Fireman Stuck in Tree",       ...

Introduction to Python Programming Course - Part 9

 Still got a fair bit with Control Flow. But looking ahead, there's not much with the other sections e.g. functions. Going to do another half hour or so - that will be it for the weekend! Start Time - 13:11 While Loops For - definite iteration. Definitive number of times the body runs.  Indefinite - this is while. A great distinction! Never got that before. So while loop ends when a condition is met. Using sum as a method.  Then pop method too. Checking the condition and running the loop until it becomes FALSE. Value of test condition has to change otherwise it would be infinite! Factorials - Practice Awesome! Got it. All  logic and all worked! Not sure about doing it with for loop - will find out... Ah yes the range option. So it would be using that method to set the parameters. Forgot that to be fair. Quiz on While loops.. Yes got this bit! Wasn't sure at first... start_num = 4 #provide some start number end_num = 12 #provide some end number that you stop when you ...