Thursday 14 November 2019

Python - Day Nineteen (November)

WHAT I DID TODAY:

Today I started on the 'Loops' unit. There were 19 lessons, so as usual, I divided it in half. I finished 9/19 lessons in this unit.


THE 9 LESSON TOPICS I COVERED


Since I only did half of it, I didn't do a review yet, but rather I did a small exercise that kind of shows everything I learned/did today.

THE EXERCISE INCORPORATING THINGS I'VE LEARNED TODAY


This may or may not look foreign, but in this exercise, I was told to write a small thing where the user has 3 guesses to guess a random number that the computer generated. If the user guesses correctly, then it prints,"You win!" but if the user guesses incorrectly, it will print,"You lose."




WHAT I LEARNED:


There are a few new things I learned today. Including what a 'loop' is or does when using Python programming. Loops execute codes repeatedly until a given condition is satisfied. 


  • The first thing I learned was condition of a loop. Basically the condition is the expression that decides whether the loop is going to be executed or not. If the loop condition for example is set to true, then only then will the loop proceed. But if it's 'false' then the loop will not execute. For a better understanding, look at the image provided below.

IT ONLY PRINTED ONCE BECAUSE THE LOOP CONDITION IS FALSE

(If the loop condition were to have been set to true, the right side would have just continuously printed, "I am a loop" with no end.)



  • The second thing I learned was the while code. When talking about loops, the while code always has to be mentioned with it because it plays a very important part in loops. It is similar to the if statement and it executes the code inside of it if the condition is true.

EXAMPLE OF THE USE OF WHILE


  • The third thing I learned was the else code. It may not be completely new but I learned it as a 'another way to use it' kind of thing. This code works with the while code and it executes anytime and every time a condition is false.

THE USE OF ELSE


(This was just a random exercise that chooses 3 random numbers, and if the number isn't 5, then the else code prints "You win!"



WHAT I WILL BE DOING TOMORROW / NEXT TIME:


Tomorrow I will continue on with the remaining lessons in the 'Loop' unit. There are 10 total lessons left. 

REMAINING LESSONS


No comments:

Post a Comment

Adobe Photoshop - Day 10 (June Final Post)

WHAT I DID TODAY / WHAT I LEARNED: For my final project, I thought for a while about what I could do. Then I remembered a while back I saw ...