Skip to content

Blackjack Game #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Blackjack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--Please do not remove this part-->
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)

# Blackjack

## 🛠️ Description

This is a simple terminal-based Blackjack game written in Python. The game follows the basic rules of Blackjack:
- Each player is dealt two cards initially.
- You can choose to draw another card (`hit`) or stop drawing (`stand`).
- The goal is to get as close to 21 as possible without going over.
- The dealer (computer) draws cards until the score is 17 or higher.
- Aces are valued as 11, but can convert to 1 if needed.

The game automatically compares scores and determines the winner at the end.

## ⚙️ Languages or Frameworks Used

- Python 3

## 🌟 How to run the script

1. Make sure you have Python 3 installed on your machine.
2. Clone this repository or copy the script into a `.py` file.
3. Open your terminal and navigate to the file directory.
4. Run the script using:

```bash
python blackjack.py
67 changes: 67 additions & 0 deletions Blackjack/blackjack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import random

def deal_card():
cards = [11, 2, 3 ,4 ,5 ,6, 7, 8, 9, 10, 10, 10, 10]
card = random.choice(cards)
return card

def calculation_start(cards):
if sum(cards) == 21 and len(cards) == 2:
return 0

if 11 in cards and sum(cards) == 21:
cards.remove(11)
cards.append(1)

return sum(cards)

def compare(u_score, c_score):
if u_score == c_score:
return "Draw"
elif c_score == 0:
return "You lose, computer has a blackjack!"
elif u_score == 0:
return "You win with a blackjack!"
elif u_score > 21:
return "You went over. You lose!"
elif c_score > 21:
return "Computer went over. You win!"
elif u_score > c_score:
return "You win!"
else:
return "You lose!"

user_cards = []
computer_cards = []
computer_score = -1
user_score = -1
game_over = False

for _ in range(2):
user_cards.append(deal_card())
computer_cards.append(deal_card())

while not game_over:
user_score = calculation_start(user_cards)
computer_score = calculation_start(computer_cards)

print(f"Your cards are: {user_cards}. Current score is: {user_score}")
print(f"Computer's first card is: {computer_cards[0]}")

if user_score == 0 or computer_score == 0 or user_score > 21:
game_over = True
else:
user_should_deal = input("Type 'y' to deal another card. Otherwise type 'n': ").lower()
if user_should_deal == 'y':
user_cards.append(deal_card())
else:
game_over = True

while computer_score != 0 and computer_score < 17:
computer_cards.append(deal_card())
computer_score = calculation_start(computer_cards)

print(f"\nYour final hand is: {user_cards}. Final score is: {user_score}")
print(f"Computer's final hand is: {computer_score}. Final score is: {computer_score}")
print(compare(user_score, computer_score))

Empty file.
Binary file not shown.
24 changes: 24 additions & 0 deletions Secret_Auction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--Please do not remove this part-->
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)

# Secret Auction

## 🛠️ Description

A simple command-line based secret auction program. Each user inputs their name and bid, and the program stores all bids in a dictionary. After all users have bid, the program reveals the winner with the highest bid. The screen is cleared after each entry to maintain secrecy.

## ⚙️ Languages or Frameworks Used

- Python 3

## 🌟 How to run the script

1. Make sure you have Python 3 installed on your machine.
2. Clone this repository or copy the script into a `.py` file (e.g., `auction.py`).
3. Ensure you have the `art.py` module in the same directory, containing the `logo` ASCII art.
4. Open your terminal and navigate to the file directory.
5. Run the script using:

```bash
python auction.py
Binary file added Secret_Auction/__pycache__/art.cpython-313.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions Secret_Auction/art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
logo = '''
___________
\ /
)_______(
|"""""""|_.-._,.---------.,_.-._
| | | | | | ''-.
| |_| |_ _| |_..-'
|_______| '-' `'---------'` '-'
)"""""""(
/_________\\
.-------------.
/_______________\\
'''
30 changes: 30 additions & 0 deletions Secret_Auction/secret_auction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from turtle import clear
from art import logo

print(logo)

bids = {}
bidding_finished = False

def find_highest_bid(bidding_record):
highest_bid = 0
winner = ""
for bidder in bidding_record:
bidding_amount = bidding_record[bidder]
if bidding_amount > highest_bid:
highest_bid = bidding_amount
winner = bidder
print(f"The winner is {winner}. With a highest bid of ${highest_bid}.")

while not bidding_finished:
name = input("What is your name? ")
bid = int(input("What is your bid? $"))
bids[name] = bid

should_continue = input("Are there any bids? Type 'yes' or 'no': ").lower()
if should_continue == "no":
find_highest_bid(bids)
bidding_finished = True
elif should_continue == "yes":
clear()