Going Up Against Python

26 Mar, 03:36 PM


On Friday March 1st, 2024 I started my journey to learn Python with Dr. Angela Yu. She begins the course very easily and introduced the first concept of the print command and explains what a string is. A string is any collection or combination of characters. An integer is a whole number while a float is any number with a decimal floating within it. The print command will then take the string you’ve written in the editor widow and display it verbatim in the output window. This is why it is important to proofread for all small details from single or double quotes, missing spaces, and the proper brackets when using an f for formatting within a string, this is called interpolation.

print(f”Your score is {score}\nCongragulations {name}!”)

This is worthy of note because without the use of an f-string Python would produce an error and be unable to combine the differing data types.

Print, Input, & If/Else:

She also spent a great deal of time explaining the difference between a print command and an input command. While both will produce a string in the output window, an input command will halt (pause) the program until it receives data from the user. The data given to input will then trigger the following commands until the program has concluded. input is capable of taking in any and all data types, this is important if you are trying to use a mathematical operation or an if/else statement. If you are using an if/else statement, but you require more if clauses you would use the elif clause which stands for “else if”. Each instance of if and elif must contain only one condition per statement and while the else clause is optional it is highly recommended as it will act as a safety net that will execute when no other special conditions are met.

if light == “green”:
elif light == “yellow”:
elif light == “red”:

Randomization, Lists, & Index:

During her randomization section she brought in the concept of lists and the use of an index. Python uses a pseudo-random number generator called the Mersenne Twister, it would take months to program the Mersenne Twister into our code ourselves so instead we import the random module. The main functions we used were random.random for random floating point numbers between 0 and 1 exclusively, but not including 1 and random.randint for random integers. For those interested these are not the only functions available, there are plenty of other functions available on askpython. Lists were our next topic and were very interesting to me. I understood the computer started counting at 0, but once I began thinking of zero as the very beginning, the ground floor, and 1 as the first step on a staircase lists became so much easier. Thankfully, Dr. Yu takes ample time and numerous examples to make sure this key way of thinking is properly absorbed. The most important part of this lesson, in my opinion, is that while random will point to a specific value out of the contents of a list index will simply tell you the value’s position within the list given the input provided. This distinction is important in order to not confuse yourself and retrieve unexpected errors. Another important function we learned was len which finds the length of a particular list, but unlike the index function the len function will count the first value in the list being 1 instead of 0. Dr. Yu put it as len tells you the number of values held within a list, but index will tell you how far away that value is from the beginning making the first value in the list 0 spots away from start.

my_list = [1, 2, 3, 4, 5, 6 ,7 ,8 ,9, 10]
##index 0 1  2  3  4  5  6  7  8  9 
##Output = 10

Python Loops:

The final section I want to discuss in this post is how Dr. Yu introduces for loops and the range function. She first identifies how the for loop should look and how it functions. The majority of the rest of the lesson is hands-on and her challenge to the student to use what they’ve learned and prove that they know how to properly use the for loop to themselves. Her approach to range was identical and I appreciate it immensely on both accounts.

for number in range(1, 11):
##This will output numbers 1-10, one integer per line

Part of my appeal to Dr. Angela’s course is her ability to nurture her students without denying their intelligence. She makes it very clear that this is new territory and there is no such thing as failure so long as you learn and keep moving forward. I am a huge fan of her teaching style and have learned a great deal in just 5 days. I am eager to continue my journey in her 100 day course.