100 Days Of Code Challenge – Level Beginner #3.

Posted in October 4, 2021 by

Categories: Challenges Programming Python

Tags: , , ,

This is a continuation of my previous articles about my experience from the 100 Days of Code Challenge in Python Udemy course made by Angela Yu.

If you would like to check previous posts here are the links:

100 Days Of Code Challenge – Day 9.

On this day Angela taught me how to use Dictionaries in Python and how to nest them in Lists or also Dictionaries.

I was doing a Students’ Grade Converter Program and at the end of this day, the main coding challenge was to make the Blind Auction Program.

You can play this simple game by clicking the link below👇 :

The whole code of this program is below👇 :

from replit import clear
from art import logo

print(logo)
bidders = {}
continue_choice = "yes"

while continue_choice == "yes":
name = input("What is your name bidder?: ")
price = int(input("What is your bid?: "))
bidders[name] = price

continue_choice = input("Is there another person to bid (yes/no)?: ").lower()
clear()
print(logo)

max_bid = 0
for key in bidders:
if bidders[key] > max_bid:
max_bid = bidders[key]
max_bid_name = key

print(f"The winner of this auction is {max_bid_name} who bid of \${max_bid}.")

And that was all for day 9 of this challenge 🙂 .

100 Days Of Code Challenge – Day 10.

On this day I was learning about the “return” statement in a function. I was learning that function can have output as it has input.

I was building the Days in Month Program that calculates how many days are in a specific month in a specific year considering that a year can be a leap year.

The final coding challenge was to create a Console Calculator.

You can check out that program by clicking the link below👇 :

The whole code for this project is below👇 :

from art import logo
from replit import clear

return n1 + n2

def subtract(n1, n2):
return n1 - n2

def divide(n1, n2):
return n1 / n2

def multiply(n1, n2):
return n1 * n2

operations = {
"*": multiply,
"-": subtract,
"/": divide,
}

def calculator():
print(logo)

num1 = float(input("What is the first number?: "))
num2 = float(input("What is the second number?: "))

for key in operations:
print(key)

operation = input("Pick an operation from the line above: ")

print("{} {} {} = {:.4f}".format(num1, operation, num2, answer))

do_continue = "y"
while do_continue == "y":

print("Type 'y' if you want to continue calculations with {:.4f} or 'n' if you want to start a new: ".format(answer))
do_continue = input()

if do_continue.lower() == "y":
num3 = float(input("What is you next number? :"))

operation = input("Pick an operation from the line above: ")

else:
clear()
calculator()

print("Goodbye!")

calculator()

And that was all for day 10 of this challenge 🙃 .

100 Days Of Code Challenge – Day 11.

On this day we were programming a console BlackJack game. In the beginning, Angela showed us a ready-to-play solution but without code and we were asked to program this on our own.

This coding challenge was a bit more difficult than previous ones but I managed quite easily to make a workable game. You can play in it by clicking the link below:

The whole code of this application you can find below👇 :

from art import logo
import random
import sys
from replit import clear

def initiate_game():
start_game = input("Do you want to play a game of Blackjack? Type 'y' or 'n': ")
return start_game.lower()

def play_again():
return input("Do you want to play again (y/n)?: ")

def take_one_card(entity_deck):
entity_deck.append(random.choice(cards))

def computer_take_one_card():
if sum(computer_deck) <= 21 and sum(computer_deck) >= 18:
return False
else:
computer_deck.append(random.choice(cards))

def initiate_game_decks():
clear()
print(logo)
global cards
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
global computer_deck
computer_deck = []
global player_deck
player_deck = []
random.shuffle(cards)
take_one_card(computer_deck)
take_one_card(player_deck)

def check_score(deck):
if sum(deck) > 21 and 11 in deck:
cards.remove(11)
cards.append(1)

def print_info():
print(f"Your cards: {player_deck}, current score: {sum(player_deck)}")
print(f"Computer's first card: {computer_deck}")
if sum(player_deck) > 21:
return "n"
player_choice = input("Type 'y' to get another card, type 'n' to pass: ")
return player_choice

def print_end_game_info():
print(f"Your final hand: {player_deck}, final score: {sum(player_deck)}")
print(f"Computer's final hand: {computer_deck}, final score: {sum(computer_deck)}")

# Black Jack info
if sum(player_deck) == 21 and len(player_deck) == 2 and sum(computer_deck) != 21:
print("BLACK JACK! You Win!")
elif sum(computer_deck) == 21 and len(computer_deck) == 2 and sum(player_deck) != 21:
print("BLACK JACK! Computer wins!")
elif sum(player_deck) <= 21 and sum(computer_deck) > 21:
print("Opponent went over. You win :-)")
elif sum(player_deck) > 21 and sum(computer_deck) <= 21:
print("You went over. Opponent win :-(")
elif sum(player_deck) > sum(computer_deck):
print("You win :-).")
elif sum(player_deck) < sum(computer_deck):
print("You lose :-(")
else:
print("It is a draw.")

continue_to_play = initiate_game()

if continue_to_play.lower() == "n":
sys.exit("Goodbye!")
else:
initiate_game_decks()

player_choice = "y"
again = "n"
while player_choice.lower() == "y" or again == "y":
take_one_card(player_deck)
computer_take_one_card()
check_score(player_deck)
check_score(computer_deck)
player_choice = print_info()

if player_choice == "n":
print_end_game_info()
again = play_again()
if again == "y":
initiate_game_decks()

And that was all for day 11 of this challenge 🙂 .

Summary.

Wow. Day 11 is already done and day 12 is ahead of me. I am very excited about what coding challenges I will have to solve.

Unfortunately, I was very busy lately and didn’t have much time to do the next few days but I am back on track with this now.