100 Days Of Code Challenge – Level Beginner #2.

Posted in June 25, 2021 by

Categories: Challenges Programming Python

Tags: , , ,

Reading Time: 5 minutes

This is the continuation of the 100 Days of Code Challenge I am participating in the Udemy course. In this article, I write about days, 5th and next.

If you still don’t know what this challenge is about please go to the link below and read the header of the article:

100 Days Of Code Challenge – Day 5.

This day was dedicated to learning loops. Angela taught me about “for” loop and how to use it with “range” key word.

I was doing code exercises where I needed to find the minimum and maximum values by using “for” loops. I also learned how to use “for” loops with step parameter.

At the end of this day, I was implementing the popular FizzBuzz game and the last coding challenge was to create a random strong password generator – PyPassword Generator ๐Ÿค“ . You can find the link to this project below๐Ÿ‘‡ :

The whole code of the last project on this day is below๐Ÿ‘‡ :

#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n")) 
nr_symbols = int(input(f"How many symbols would you like?\n"))
nr_numbers = int(input(f"How many numbers would you like?\n"))

#Eazy Level 

py_password = ""
for _ in range(nr_letters):
  letter = random.choice(letters)
  py_password += letter

for _ in range(nr_symbols):
  symbol = random.choice(symbols)
  py_password += symbol

for _ in range(nr_numbers):
  num = random.choice(numbers)
  py_password += num

#Hard Level

py_password_list = list(py_password)
random.shuffle(py_password_list)
py_password = "".join(py_password_list)

print(f"Your password is: {py_password}")

And that is all for day 5 of 100 Days of Code Challenge ๐Ÿ™‚ .

100 Days Of Code Challenge – Day 6.

This day was all about functions and little about debugging.

We used Reeborg’s World website to learn how to program a robot on a board to move to a certain position.

On this day very helpful was “while” loop.

The final code challenge was to debug 3 cases where robots were stuck in an infinite loop, moving in a square, instead of heading to a goal.

Unfortunately, I failed to solve this challenge on my own. I tried to write a code that was detecting if a robot is in a loop or not but it was flawed and didn’t work.

I noticed I have a tendency to patch code rather than fully understand a problem and make a final adjustment. I think this is one of the flaws I would like to change during this course.

The solution was to create an additional, separate “while” loop and move forward until the robot wasn’t in front of the wall. Then the robot turns left and the main loop executes.

The link to the code for this final assessment you can find below:

And that is all for day 6 of 100 Days of Code Challenge ๐Ÿ™ƒ .

100 Days Of Code Challenge – Day 7.

On this day we were creating the console Hangman Game.

If you have never played in this game before you can try this link to give it a try:

On this day I learned how to code more complex projects. To be honest, Hangman is a very small project but for a beginner, it can be quite challenging.

You can play the game I wrote on this day by clicking the link below:

The full code of this game is below:

import random
from hangman_words import word_list
from hangman_art import stages
from hangman_art import logo
from replit import clear

chosen_word = random.choice(word_list)
word_length = len(chosen_word)

end_of_game = False
lives = 6

print(logo)

#Testing code
# print(f'Pssst, the solution is {chosen_word}.')

display = []
for _ in range(word_length):
    display += "_"

print(f"{' '.join(display)}")
while not end_of_game:
    guess = input("Guess a letter: ").lower()

    clear()
    if guess in display:
        print(f"You already guessed the letter '{guess}'.")

    for position in range(word_length):
        letter = chosen_word[position]

        if letter == guess:
            display[position] = letter

    if guess not in chosen_word:

        print(f"The letter {guess} is not in the chosen word. You lose live.")
        lives -= 1
        if lives == 0:
            end_of_game = True
            print("You lose.")

    print(f"{' '.join(display)}")

    #Check if user has got all letters.
    if "_" not in display:
        end_of_game = True
        print("You win.")

    print(stages[lives])

And that is all for day 7 of 100 Days of Code Challenge ๐Ÿ™‚ .

100 Days Of Code Challenge – Day 8.

On this day I learned how to program Caesar Cipher but before that, I was learning about passing an argument to a function and using function parameters inside it.

I was programming Wall Paint Calculator and Prime Number Checker. These tasks were super easy for me.

The final coding challenge was to program the Caesar Cipher program. It was quite easy too.

You can check it under the link below:

You can find the full code of this project below:

from art import logo

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def caesar(start_text, shift_amount, cipher_direction):
  end_text = ""
  if cipher_direction == "decode":
    shift_amount *= -1
  for char in start_text:
    if char in alphabet:
        position = alphabet.index(char)
        new_position = position + shift_amount
        end_text += alphabet[new_position]
    else:
        end_text += char
    
  print(f"Here's the {cipher_direction}d result: {end_text}")

print(logo)

choose = "yes"
while choose == "yes":
    direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
    text = input("Type your message:\n").lower()
    shift = int(input("Type the shift number:\n"))

    if shift > 26:
        shift = shift % 26

    caesar(start_text=text, shift_amount=shift, cipher_direction=direction)
    choose = input("Do you want to restart caesar cipher program (yes/no)?: ")

And that is all for day 8 of 100 Days of Code Challenge ๐Ÿ™ƒ .

Continuation.

I will end this article on day 8.

The next days will be posted soon.

You can already check if article #3 of this challenge is present on my blog by clicking the link below:

If the link doesn’t work it means that I am still working on the next days.

I hope you find those articles valuable and if you would like to join to 100DaysOfCode Challenge you can do that by clicking the link below:

Thank you for reading and have a great day.

Cheers ๐Ÿ‘‹ .



Leave a Reply

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

10 − five =

error: Content is protected !!