PROject Python | Blackjack (#extremely.cool.it’s.kinda.unbelieveable,just.saying)

Quote of AWESOMENESS: “Thinking is already a conversation” ~ Paul Pangaro

 

Hey there!

I know it’s been awhile but here I am with another Python project. Today, you will be learning the code for blackjack! Just put it out on your editor, study the code, and explore the game on your terminal. It was quite some challenge getting toward the end of finishing up the game. And, at some point, problems and bugs constantly came up that I didn’t that it would actually get done. BUT, nevertheless, it’s finally hereeee!!

*ahem, drum rollllllllll*

*cricket sounds*

*Umm….. DRUMMM ROLLLL!!!……. please?*

*DRUM ROLLLLLLLLLL (in the background, finally)*

TADA!!!!:

#import the random library from python
from random import *


#Function Definitions 
def deal_from_deck(deck):
    if len(deck)<1:
         create_deck(deck)
         shuffle_deck(deck)
         deal_cards()

def deal_cards(deck):
    return deck.pop(0)

def define_cards(n):
    rank_string = ("ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen","king")
    suit_string = ("clubs", "diamonds", "hearts", "spades")
    cards = []

    for suit in range(4):
        for rank in range(13):
            card_string = rank_string[rank] + " of " + suit_string[suit]
            cards.append(card_string)
    return cards[n]

def create_deck(deck):
    for i in range(52):
        deck.append(i)
    return

def shuffle_deck(deck):
    shuffle(deck)
    return

def card_value(n):
    vals = (11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10)
    card_vals = []

    for s in range(4):
        for r in range(13):
            card_vals.append(vals[r])
    return card_vals[n]

def card_display(n):
    name = define_cards(n)
    val = card_value(n)
    print (name + " : " + str(val))

def show_cards(hand):
    for card in hand:
        card_display(card)


def hand_val(hand):
    list = []
    for card in hand:
        list.append(card_value(card))
    if sum(list) > 21:
        for i in range(len(list)):
            if list[i] == 11:
                list[i] = 1
    return sum(list)





# Initializing
drawn_hands = 0
player_wins = 0
dealer_win = 0
deck = []
player_hand = []
dealer_hand = []
playing = True


#Processing
create_deck(deck)
shuffle_deck(deck)

for i in range(2):
    card = deal_cards(deck)
    card2 = deal_cards(deck)
    player_hand.append(card)
    dealer_hand.append(card2)


# put in a loop for player hand
print()
print("--------------------")
print("Dealer shows: ")
card_display(dealer_hand[0])
print("--------------------")

while playing == True:
    player_val = hand_val(player_hand)
    print()
    print()
    print("* * * * * * * * * * *")
    print("Your current hand is...")
    show_cards(player_hand)
    print(hand_val(player_hand))
    print("* * * * * * * * * * *")
    print()
    print()
    if player_val < 22:
        response = input("Would you like another card?")
        if response == "yes":
            player_hand.append(deal_cards(deck))
        else:
            playing = False
    else:
        playing = False
        print("sorry you busted")
        print("Thanks for playing")
        exit()

# check if it is higher than 21, if yes then end program, dealer hand wins
show_cards(dealer_hand)

playing = True
while playing == True:
    if hand_val(dealer_hand) < 17:
        dealer_hand.append(deal_cards(deck))
    else:
        playing = False

print()
print()
print("****************")
print("Dealer has:")
print(show_cards(dealer_hand))
print("****************")
print()
print()

if hand_val(dealer_hand) > 21:
    print("The dealer busted")
    show_cards(dealer_hand)
    print("You win!")
    exit()
elif hand_val(dealer_hand) > hand_val(player_hand):
    print("Dealer wins")
    show_cards(dealer_hand)
    exit()
elif hand_val(player_hand) > hand_val(dealer_hand):
    print("You win!")
    show_cards(player_hand)
    exit()
else:
    print("It's a draw")
    exit()

 

don’t forget to smile & be awesome 🙂

Yours truly, 

L.O.A.S.H

 


 © Elizabeth Anne Villoria

L.O.A.S.H’s Arduino Projects: Controlling Servo Motors with a Joystick

With this project, you will be able to control two servo motors with a joystick with Arduino! 

For this project you will need to gather:

  • Arduino Board

0-02-06-3e61517352900af7aca75ae80bd8bb003f5bb9e72a9e9557f75162f83bbd25fa_full.jpg

  • Breadboard

0-02-06-cd66c6b6d65f22179fc1a06c362c44db50bc340f3218d339911b1eb0709a55b8_full.jpg

  • Wires | x13

0-02-06-b48c27591fb83fd36c03c33e241a51a1f619e6b1d07f0de5cb66f1b076e17d8b_full

  • Servo Motors | x2

0-02-06-656ab4f6bc88f237b866d892bdb219fefa5e480bf645f88fc2cbfc55f749f569_full

  • Battery 

0-02-06-8ac9e32dd7aa2cab229409c610e5218da78fd9469262db96a33691471e1b1a6b_full

 

To make this (really cool) project, you will need to:

Step 1: Battery

Connect your external battery to your breadboard.

0-02-06-fa93aff5c167975906e799e6193fd5bb7e4fdcd8271bcebacdfc368bc592e900_full  

Step 2: Wiring 

Get a piece of wire and connect one end to GND on your Arduino Board and the other end to the negative channel on your breadboard.

0-02-06-fb2c30416f0bc5b94c8d3c9d743bffc1439a17d6e5c06e1fe5028219feafe597_full

Step 3: Servo Motors

Get your two servo motors and 6 wires. Connect the VCC and the GND of the two servos to the VCC and GND on the breadboards inputs. Then, connect your first Servo Signal Connect to the Arduino Digital PMW 3 on your Arduino Board.

0-02-06-3daf95e97aa092d7453a4010191438347de1b18e134785dded2454d5d49c5d69_full

 In case you aren’t very familiar with the Arduino Digital PMW 3, it looks like the photo below as well as the Digital PMW 5 and the blue wire from the first servo

0-02-06-24edbd7bb8929ca5eab0480444ddfbfd4030d44cc1b9499de030c0acd518d611_full

Your second Servo Signal Connect should be connected to the Arduino Digital PMW 5.

0-02-06-a98f20a183f18ace8fc31c4260055729730df7fcbc957b428a9d8c2ed68210af_full

Step 4: JoyStick

Connect the GND on your Joystick to the GND on the Arduino Board.

0-02-06-750f14cd78d2d4ccb1571cc4bb98c5cce58194a7654087ed21c9b2f5a411bcaa_full

Then, connect the +5V on your joystick to the 5V on the Arduino Board.

Then, connect the VRx on your joystick to the A0 on the Arduino Board.

Then, connect the VRy on your joystick to the A1 on the Arduino Board.

The photo below shows where I connected what and where. Just look at the corresponding colors to which wire and the connection.

0-02-06-5542b4f4d9b290f3f778bc26fd3dc21fc12fd4cef7fe95ce67ab70ada427e734_full

It also looks something like this….

Screen Shot 2017-07-03 at 13.40.11

 

Step 5:  The Code

Open up your Arduino on your computer and copy the code below:

//add the servo library
#include <Servo.h>

//define our servos
Servo servo1;
Servo servo2;

//define joystick pins (Analog)
int joyX = 0;
int joyY = 1;

//variable to read the values from the analog pins
int joyVal;

void setup() 

{ //attaches our servos on pins PWM 3-5
servo1.attach(3);
servo2.attach(5); }

void loop() 

{ //read the value of joysticks (between 0-1023)
joyVal = analogRead(joyX);
joyVal = map (joyVal, 0, 1023, 0, 180);
servo1.write(joyVal);

joyVal = analogRead(joyY);
joyVal = map(joyVal, 0, 1023, 0, 180);
servo2.write(joyVal);
delay(15); }

Screen Shot 2017-07-03 at 13.54.02

Step 6: Verify, Connect and Upload

Once you verify and save the code, you can connect your Arduino board to your computer and upload the code to your board. Tada! 

Step 7: Have fun and Experiment

Yay! We’ve finally finished yet another Arduino Project. You guys are so awesome! Now, after playing around with this, you can try to experiment maybe add more things (an example, “lights, perhaps?”).

Wait, if you are having any problems uploading or your project isn’t functioning properly, you should double check your wiring and maybe check which Port your Arduino (on your computer) connected to in the tools. If there is anything else don’t be shy to comment down below!

Screen Shot 2017-07-03 at 13.57.45

 

Yours truly, 

L.O.A.S.H

 

 

Project Python | Command Line Calender

You can make your own calendar and even add, update and view.

For your python code, copy and paste the following:


from time import sleep, strftime
name = “Libster”calendar = {}
def welcome():    print(“Welcome, ” + name + “!”)    print(“Calendar starting…”)    sleep(1)    print (“Today is “) + strftime( “%A %B %d, %Y”)     print (“The time is “) + strftime(“%I:%M:%S”)    sleep(1)    print(“What would you like to do?”)    def start_calendar():  welcome()  start = True  while start:    user_choice = raw_input(“Please choose A to Add, U to Update, V to View, X to Exit. “)    user_choice=user_choice.upper()    if user_choice == “V”:      if len(calendar.keys()) <1:        print “Your calendar is empty”      else:        print calendar    elif user_choice == “U”:        date = raw_input(“What date? “)        update = raw_input(“Enter the update: “)        calendar[date] = update        print(“Update successful.”)        print calendar    elif user_choice == “A”:        event = raw_input(“Enter event: “)        date = raw_input(“Enter date (MM/DD/YYYY): “)        if len(date) > 10 or int(date[6:]) < int(strftime(“%Y”)):            print(“Invalid date.”)              try_again = raw_input(“Try again? Y for Yes, N for No: “)            try_again = upper.try_again()            if try_again == “Y”:                continue            else:                start = False            else:            calendar[date] = event            print(“Event update successful.”)            print calendar    elif user_choice == “D”:        if calendar.keys(len(date)) < 1: #check this line if fail            print(“The calendar is empty.”)        else:            event = raw_input(“What event?”)             for date in calendar.keys():                if event == calendar[date]:                     del calendar[date] # deletes entire entry, inc date & event                print(“Event deleted.”)                print calendar            else:                print(“Incorrect date.”)    elif user_choice == “X”:        start = False    else:        print(“Invalid command.”)        breakstart_calendar()


 

Then in the command line, play your python code.

Screen Shot 2017-07-02 at 17.40.47

Above, the picture is an example of how it should turn out to be. I added an event, updated that same event and viewed! Don’t forget to try to experiment and maybe make this cooler.

Yours truly,

L.O.A.S.H

L.O.A.S.H’s Guide to (nearly) Everything: Restarting Storage on Your Mac (Easy)

We wanted to clear the storage in our Mac Book but deleting all the files in the finder and countlessly searching on the internet didn’t seem to be helping us achieve our goal. If you go to the About this Mac, and select storage, you would see something like the screenshot below:

 Screen Shot 2017-06-24 at 09.05.35.png

My mom kept murmuring about that she couldn’t delete her movies and that it was taking up to much storage space on her computer. I deliberately went to her to stop the fuss. In this blog, you will learn how to make your storage space lessened.

Step 1:

Go to System Preferences.  Screen Shot 2017-06-24 at 09.22.21.png <— Looks like this. If you have a hard time looking for it, you can find it the spotlight at the top right area of your computer screen. It looks like a magnifying glass. Screen Shot 2017-06-24 at 09.24.18.png

Step 2:

When you open up your System Preferences, go to Startup Disk. I circle on the screenshot below.

 Screen Shot 2017-06-24 at 09.25.34

Step 3:

When you are already on your Startup Disk, select theScreen Shot 2017-06-24 at 09.31.12.png following to make changes. When you click on this, a verification will pop up asking you to put your password of your computer. Put your password and click Unlock.Screen Shot 2017-06-24 at 09.33.08.png

 

 

 

 

Step 4:

When you are able to make changes, select the system and press Restart.

Screen Shot 2017-06-24 at 09.35.25.png

First, Select your system.

 

 

 

Screen Shot 2017-06-24 at 09.36.29.png
Then, select Restart.

 

Step 5:

After your computer restarts, you will be asked to sign in to your apple id. And, Tada!

Yours truly,

L.O.A.S.H