Python Lesson 4

Today, we learnt about If-Else statements. An If-Else statement is where if the input satisfies the code, then a certain function would take place. If the input does not satisfy, then the code under ‘else’ would run. This ‘else’ code would only run if the requirements aren’t met. This loop can be useful as it gives feedback to the user if the conditions haven’t been met.

Something else that we learnt about today was the ‘Elif’ function. Like If-Else statements, the ‘Elif’ function is also very useful. An ‘Elif statement allows the code to check the validity of multiple variables at the same time. This is extremely useful since instead of of having to write out many lines of ‘if’ statement loops, we can shorten and condense that code to one line. This way, we can save time by not having to write as many lines of code but still be able to have the same outcome in the end.

One of the projects that we did in class today was a ‘vowel’ counter. This series of code was written to count the value of a word based on how many vowels there were in that word.

This series of code uses the ‘elif’ function to define which letters are vowels and how many points they’re worth. Once the user inputs their name or their word of choice, the code then counts the number of vowels in that words and then assigns a score based on what each vowel is worth.

Moving on, we also started writing the pseudo code for a guess the word game. This game uses all of the functions that we have learnt today so far.

-insert images when olivia sends them…-

So far, we have decided to use food options. Since my laptop was under repair and I couldn’t use PyCharm, I had to write out the code on a separate document. Here’s what it looks like so far:

import random

vChoices = (“fries”, “chips”, “cookie”, “burger”, “sushi”, “apple”)

vWord = (random.choice(vChoices))

vName=input(“whats yo name?”)

In order to make sure that theres a limit on what words the computer can choose to use, we decided to limit the computer so it would be a lot easier for the user to guess within 6 words rather than an infinite number.

Today, I also learnt when it is appropriate to use whichever type of loop. The ‘while’ loop is a good option to use when coding if there are multiple situations since it won’t pass unless a certain condition is met. This way, the loop is solid and closed, leaving no room for error. Meanwhile, a ‘for’ loop also has its own benefits. This loop is good to use when there is a known number of times something will repeat. Even though there will be a lot of inputs, the code will only pass after the correct input is inserted.