Posts

Showing posts from November, 2022

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 ...

Introduction to Python Programming Course - Part 8

 Weekend entry - part 1! The current focus is control flow. I really got into for loops last time - lots to pick up on there. Let's go! Start Time - 10:16 Building Dictionaries So you can create a list, then iterate over each item to add to an empty dictionary, of the count. So if the word isn't already there, it sets to 1. Then adds one on if already there. Got it. The other way is the 'get' method.  First method practice -  driver_winners_2022 = ["Leclerc", "Verstappen", "Leclerc", "Verstappen", "Verstappen", "Perez", "Verstappen", "Leclerc", "Verstappen", "Verstappen", "Sainz", "Verstappen", "Russell", "Verstappen"] driver_winners_count = {} for driver in driver_winners_2022:     if driver not in driver_winners_count:         driver_winners_count[driver] = 1     else:         driver_winners_count[driver] += 1              print(d...

Introduction to Python Programming Course - Part 7

Right here we go for the weekday coding! This section is all about control flow. Last time it was the basics of if statements and conditionals - certain keywords, use of operators etc. Let's go! Start Time - 19:28 For Loops These are for iterating - do something repeatedly.  An iterable - something that can return one element at a time. So it could be items in a list.  I remember these from before - useful for when going through a sequence of numbers. For strings in this list example, using the title method just gives the name. An empty list, then for something in something - add them to this. Again with the title - property? Range So with range, it is the number of elements that are then accessed. Or it can be specific items. Or in range - just numbers up to that point. OK this stuff is tricky. The hardest up to this point - I need practice with this and NOT rush through it! Indentation - important here. If not indented, then it means that this is separate. Will explain more....

Introduction to Python Programming Course - Part 6

So last time it was all about data structures - the key parts being mutability and ordered/not. From that, specific methods with each the structures - lists (formerly arrays in swifts), dictionaries, sets and tuples. All of it made sense and nothing too conceptually tricky. Now I'm on the 3rd section of Python - Control Flow! Start Time - 22:32 (late night quick session!) So this is all to do with loops, conditionals etc. If Statement  Key difference to Swift: colon is used rather than curly brackets. Boolean used to return true/false and then an action happening.  If - runs or skips code depending on if a condition is true or false. If false then those lines not executed.  Use of == as equal to, != or use of < etc. 'Elif' - new keyword! So this would be else if but combined to Elif.  Else is best for if there is only a second option. If there are multiple, then Elif. Else can also be seen as all other options.  Indentation convention - 4 spaces to indent. So...

Introduction to Python Programming Course - Part 5

OK, I'm doing this gradually. Things are soaking in and making sense. Nothing too hard has come up. Let's do a recap before I crack on... Last time it was about data structures rather than types. So things like lists, sets. These can be of different types but are their own structures - they follow a certain syntax and have different functions. Tuples too.  Start time - 17:20 Dictionaries These are a mutable type. Keys to values - same as Swift. Curly brackets. Keys don't even need to be the same type; as long as it's consistent.  Use 'in' as keyword to check if a value is there. 'Get' method - but returns none if a value is not. Need to look more at that. OK using the square bracket lookup can lead to crashes. Get is safer. Is and is not - So using is followed by 'none' or is not followed by 'none' would lead to a true or false Quiz - all good. I get the basics of the key/value pair and trying to access.  A point on == and is. Is means th...

Introduction to Python Programming Course - Part 4

Onto the next section - concepts! Data Structures. I remember doing 'structs' and 'classes' with Swift and these were always tricky. Yes this is all about grouping together different types. Also going to learn about membership and identity - not sure what those terms mean, so am looking forward to finding out! 2. Lists and Membership Operators Containers - contain data types and other containers! Lists - I think these are the equivalent of arrays E.g. months of the years - contain strings (the months). Square brackets. Ordered - yep the same as array. Indexes etc. First element is 0. Think of it as how far away from the beginning of the list.  -1 index is the last index item, -2 is second to last etc. Not -0! List index exception - error to show if trying to access item that is not there - will show you how far off etc. 3. Quiz - lists and membership operators and 4. solution One of those terms. Membership makes sense - items that are members in a list.  Nailed question...

Introduction to Python Programming Course - Part 3

Getting some momentum going! And not that many more parts to this types and operations bit of the course. Last time it was all about Ints, Floats, Bools and Strings - different types and ways of using different operators with them.  Start Time - unknown 22. String Methods Practice \n - special way of putting in a line break.  OK learned some new methods! verse_length = len(verse) print(verse_length) print(verse.find("and")) print(verse.index("and")) print(verse.rfind("you")) print(verse.count("you")) So find and index - at what character index does 'and' first appear; rfind - last appear for "you" and count is of a specific string within a string "you". Had to look them up but that's good - that was the point of this challenge! One thing I didn't do was the descriptive message. For that it is using the 'format' function.  Use of {} for the missing values. Let's just practice that... This is what the...

Introduction to Python Programming Course - Part 2

Here we go! As promised, approximately one hour during the week and one at the weekend. I'm going to do about that long today - hopefully getting to a natural point.  I think it's useful to begin with a recap from before...  Last time it was about data types (the four operations plus others such as modulo, increments etc.), creating variables (no var/let keyword needed and naming conventions with _). Next! Start Time - 13:26 8. Integers and Floats Whole numbers (integers) we've been looking at. Decimal numbers - used as floats (floating point number).  You need to include a decimal point e.g. .0 do declare a float. An int and float together will always make a float.  A float to int just cuts off the decimal values, no rounding.  Floating point numbers are approximations.  About best practices - Conventions - not using extra spaces in parentheses etc. A space around the lower priority e.g. where you have x and -. Space around the -. 79-99 characters per line...

Introduction to Python Programming Course - Part 1

Installing was pretty simple! All done and not much space required on the Mac. Not compared to Xcode! Now I'm all set up with that, the next step is to find a good taster course - something simple and easy just to whet the whistle.  I've browsed few a few websites and some have the 'zero to hero' tagline, or words to that effect. In my experience, these are too all-promising and tail off in quality as there is no way that one course is enough to make you an expert! So I'm looking for something simpler... OK this looks like a good option. Something I can do in a few weeks i.e. by the Christmas break: https://www.udacity.com/course/introduction-to-python--ud1110?irclickid=22qQR81oYxyNTO%3AxIyRKFQoZUkDXi43v5Qxy1s0&irgwc=1&utm_source=affiliate&utm_medium=&aff=1359419&utm_term=&utm_campaign=_best9python9courses_&utm_content=&adid=786224 Let's get stuck in! Start Time: 18:06 Part 1 - Introduction 1 - Welcome Python one of the most widel...