100 Days Of Code Challenge – Level Beginner #4.

Posted in November 1, 2021 by

Categories: Challenges Programming Python

Tags: , , ,

Reading Time: 5 minutes

This is a continuation of a 100 Days of Code Udemy course challenge made by Angela Yu.

If you would like to see previous days you can find them on my blog.

The last previous article from this category is under this link:

100 Days Of Code Challenge – Day 12.

On this day I learned about scopes. Angela showed us that there can be inside a scope, outside scope, and block scope.

I learned that when you create a variable in Python inside the “if” statement or a loop it has a global scope. It is a bit strange in comparison to other languages like JS or Java.

Angela showed us also how to create a constant.

The final coding project was to create a Number Guessing Game. The solution code was shown at the end of this section but Angela ask me to code my solution first before seeking the answer.

This coding challenge was super easy for me because I coded it many years ago.

So you can play this binary search number game under the link below๐Ÿ‘‡ :

The whole code of my solution is below๐Ÿ‘‡ :

from art import logo
import random

target = random.randint(0, 100)
guess_num = None

def print_welcome():
    print("Welcome to the Number Guessing Game!")
    print("I'm thinking of a number between 1 and 100.")

def initialize_game():
    mode = choose_mode()
    guess_num = calc_num_avail_guesses(mode)
    print(f"You have {guess_num} attempts remaining to guess the number.")
    return guess_num

def print_hint():
    print(f"Pssst, the correct answer is {target}.")

def choose_mode():
    mode = input("Choose a difficulty. Type 'easy' or 'hard': ")
    return mode

def calc_num_avail_guesses(mode):
    if mode.lower() == "easy":
        return 10
    elif mode.lower() == "hard":
        return 5
        return 10 

guess_num = initialize_game()

while guess_num > 0:
    guess = input("Make a guess: ")
    guess = int(guess)
    if guess < target:
        print("To low.")
        print("Guess again.")
        guess_num -= 1
        print(f"You have {guess_num} attempts remaining to guess the number.")
    elif guess > target:
        print("To high.")
        print("Guess again.")
        guess_num -= 1
        print(f"You have {guess_num} attempts remaining to guess the number.")
        print(f"You got it! The answer was {target}.")

if guess_num <= 0:
    print("You lose. Try again :-).")

And that is all for day 12 ๐Ÿ™‚ .

100 Days Of Code Challenge – Day 13.

Day 13 is all about debugging.

Angela is showing that code can have different bugs in it. Simple ones can be found quite easy for example by changing the iteration numbers in the range function in a loop.

More difficult bugs to find are for example the ones that only show when certain conditions are met. It can be found for example when we use randomly generated numbers with lists.

The instructor also says that the “print” function is very helpful in debugging. I must write that I use “print” a lot in debugging my code ๐Ÿค“ .

I am aware that the more bugs I will fix in my projects the better programmer I will become. Angela is mentioning that in her course.

A good tip for fixing bugs in code is just simply taking a break. When you take a break and come back after some time you can see your problem from a different perspective.

Another good tip in solving problems with code is to run your code often. When you run your code often you can tackle the fewer amount of bugs at one time.

When you run your code after writing a lot of it, it probably has a lot of bugs.

The last tip for debugging I learned this day is to ask other people what they think about your code. You can ask your mentor, your work colleague or you can ask on Stack Overflow.

When I was debugging my code and I got stuck I often used the Stack Overflow website to seek solutions. It is a great resource for every programmer.

At the end of this day, Angela gave us three debugging exercises. The last one was the final coding challenge.

The final debugging challenge is below๐Ÿ‘‡ :

for number in range(1, 101):
  if number % 3 == 0 or number % 5 == 0:
  if number % 3 == 0:
  if number % 5 == 0:

And my solution is๐Ÿ‘‡ :

for number in range(1, 101):
  if number % 3 == 0 and number % 5 == 0:
    print(f" {number} = FizzBuzz")
  elif number % 3 == 0:
    print(f" {number} = Fizz")
  elif number % 5 == 0:
    print(f" {number} = Buzz")

And that is all for day 13 ๐Ÿ™ƒ .

100 Days Of Code Challenge – Day 14.

On this day there is only one final coding challenge to code. This is the last day of beginner level in Angela’s course ๐Ÿค“ .

The final coding challenge is to code a Higher Lower Console Game.

The live, online example of this game is under this link:

Angela doesn’t give us any starting code, so participants of her course must write this project from scratch.

I must write that it was quite easy for me.

Here you can play in my console version of Higher Lower Game๐Ÿ‘‡ .

And here is the code of the whole game๐Ÿ‘‡ :

from art import logo
from art import vs
from game_data import data
import random
from replit import clear

score = 0
data_copy = []

def pick_info_block():
    random_number = random.randint(0, len(data) - 1)
    data_item = data[random_number]
    del data[random_number]
    return data_item

def print_game_info():
    print(f"Compare A: {data_a['name']}, a {data_a['description']}, from {data_a['country']}.")
    print(f"Against B: {data_b['name']}, a {data_b['description']}, from {data_b['country']}.")

flag_first = True
flag_right = False
while len(data) != 1:
    if flag_first:
        data_a = pick_info_block()
        data_b = pick_info_block()
        flag_first = False
        data_a = data_b
        data_b = pick_info_block()

    if flag_right:
        print(f"You're right! Current score: {score}.")

    guess = input("Who has more followers? Type 'A' or 'B': ")
    if guess.upper() == "A":
        if data_a['follower_count'] > data_b['follower_count']:
            score += 1
            flag_right = True
            print(f"Sorry, that's wrong. Final score: {score}")
    elif guess.upper() == "B":
        if data_a['follower_count'] < data_b['follower_count']:
            score += 1
            flag_right = True
            print(f"Sorry, that's wrong. Final score: {score}")
        print("Invalid input. Thank you for game.")

    if len(data) <= 2:
        data = data_copy.copy()
        data_copy = []

And that is all for day 14 ๐Ÿ™‚ .


To sum up, the beginner level is done.

I am quite proud of myself because almost all the final coding exercises I did on my own.

Now the intermediate level is ahead of me.

Thank you for reading my articles.

Have a great day.

Bye ๐Ÿ‘‹ .

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!