Skip to content
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
53 changes: 53 additions & 0 deletions blackjackgame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Create a deck of 52 cards,Shuffle the deck
# Ask the Player for their bet
# Make sure that the Player’s bet does not exceed their available chips
# Deal two cards to the Dealer and two cards to the Player
# Show only one of the Dealer’s cards, the other remains hidden
# Show both of the Player’s cards
# Ask the Player if they wish to Hit, and take another card
# If the Player’s hand does not Bust (go over 21), ask if they’d like to Hit again.
# If a Player Stands, play the Dealer’s hand. The dealer will always Hit until the Dealer’s value meets or exceeds 17
# Determine the winner and adjust the Player’s chips accordingly
# Ask the Player if they’d like to play again

# declare the deck cards

import random

suits = ('club', 'hearts', 'diamond', 'spade')
ranks = ('two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'jack', 'queen', 'king', 'ace')
values = {'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'ten': 10,
'jack': 10, 'queen': 10, 'king': 10, 'ace': 11}


# created a class for the card with only two attribute suit and rank then created function for both
class card:
def __init__(self, suit, rank):
self.suit = suit
self.rank = rank

def __str__(self):
return self.rank + 'of' + self.suit


# lets create a deck that has 52 cards
def shuffle(self):
random.shuffle(self.deck)


class deck:
def __init__(self):
self.deck = {}
for suit in suits:
for rank in ranks:
self.deck.append(card(suit, rank))

def __str__(self):
deck_com = '' # empty string
for card in self.deck:
deck_com += '/n' + card.__str__() # add each card object's print string
return 'the deck cards has' + deck_com

def deal(self):
single_card = self.deck.pop(self)
return single_card
80 changes: 80 additions & 0 deletions calculator with tinkter/tkintercalc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import tkinter as tk

calc = tk.Tk()
calc.title("CrappyCalc")

buttons = [
'7', '8', '9', '*', 'C',
'4', '5', '6', '/', 'Neg',
'1', '2', '3', '-', '$',
'0', '.', '=', '+', '@']

# set up GUI
row = 1
col = 0
for i in buttons:
button_style = 'raised'
action = lambda x=i: click_event(x)
tk.Button(calc, text=i, width=7, height=7, relief=button_style, command=action) \
.grid(row=row, column=col, sticky='nesw', )
col += 1
if col > 4:
col = 0
row += 1

display = tk.Entry(calc, width=40, bg="white")
display.grid(row=0, column=0, columnspan=5)


def click_event(key):
# = -> calculate results
if key == '=':
# safeguard against integer division
if '/' in display.get() and '.' not in display.get():
display.insert(tk.END, ".0")

# attempt to evaluate results
try:
result = eval(display.get())
display.insert(tk.END, " = " + str(result))
except:
display.insert(tk.END, " Error, use only valid chars")

# C -> clear display
elif key == 'C':
display.delete(0, tk.END)


# $ -> clear display
elif key == '$':
display.delete(0, tk.END)
display.insert(tk.END, "$$$$C.$R.$E.$A.$M.$$$$")


# @ -> clear display
elif key == '@':
display.delete(0, tk.END)
display.insert(tk.END, "wwwwwwwwwwwwwwwwebsite")


# neg -> negate term
elif key == 'neg':
if '=' in display.get():
display.delete(0, tk.END)
try:
if display.get()[0] == '-':
display.delete(0)
else:
display.insert(0, '-')
except IndexError:
pass

# clear display and start new input
else:
if '=' in display.get():
display.delete(0, tk.END)
display.insert(tk.END, key)


# RUNTIME
calc.mainloop()
20 changes: 20 additions & 0 deletions python calculator
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#calculator build in python
#addition

#define the functions
#add function
def add(x, y)
return x+y

#this function substract
def subtract(x, y)
return x - y

#this function multiplies two numbers
def multipy(x, y)
return x * y

#this function divides two numbers
def devide(x, y)
return x / y

57 changes: 57 additions & 0 deletions python calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# calculator build in python
# addition

# define the functions
# add function


def add(x, y):
return x + y


# this function subtract
def subtract(x, y):
return x - y


# this function multiplies two numbers
def multiply(x, y):
return x * y


# this function divides two numbers
def divide(x, y):
return x / y


print("Please select operation \n"
"1. Add\n"
"2. Subtract\n"
"3. Multiply\n"
"4. Divide\n")

select = float(input("Please select 1 2 3 4 :"))
# define the parameters
number_1 = float(input("Enter your first number"))
number_2 = float(input("Enter your first number"))
# do the calculation
# addition
if select == 1:
print(number_1, "+", number_2, "=", add(number_1, number_2))

# subtraction

elif select == 2:
print(number_1, "+", number_2, "=", subtract(number_1, number_2))

# multiplication

elif select == 3:
print(number_1, "+", number_2, "=", multiply(number_1, number_2))

# division

elif select == 4:
print(number_1, "+", number_2, "=", divide(number_1, number_2))
else:
print("wrong input ")