<jupyter_start><jupyter_text>object oriented programming assignment 2<jupyter_code>class account():
    
    def __init__(self,owner,balance,deposit,withdraw):
        self.owner = owner
        self.balance = balance
        self.deposit = deposit
        self.withdraw = withdraw
    def config1(self):
        self.balance = self.balance + self.deposit
        
       
    def config2(self):
        if self.balance >= self.withdraw:
            self.balance = self.balance - self.withdraw
            print("The balance of the account holder is {}".format(self.balance))
            print("withdrwal successfull :)")
            
        elif self.balance < self.withdraw:
            self.balance = self.balance - self.withdraw
            print("The balance is {}".format(self.balance))
            print("you have insufficient fund ....brainless!!")
           
            
            
            
            
    
    
            
        
      

q = str(input("Enter the name of the account holder:"))
w = int(input("Enter the amount that you want to deposit:"))
e = int(input("Enter the amount that you want to withdraw:"))

        
        
        
        
omr = account(q,0,w,e)

omr.config1()
omr.config2()<jupyter_output>Enter the name of the account holder:neeraj
Enter the amount that you want to deposit:1000
Enter the amount that you want to withdraw:2000
The balance is -1000
you have insufficient fund ....brainless!!<jupyter_text>EXCEPTION HANDLING AND CREATING A FILE<jupyter_code>try:
    result = 10 + 10 
except:
    print("hey its looks like you are making some mistakes!!")
    
else:
    print(result)
finally:
    print("this statement will be excecuted if there is error also")
    
try:
    result = 10 + "10" 
except:
    print("hey its looks like you are making some mistakes!!")
    
else:
    print(result)
finally:
    print("this statement will be excecuted if there is error also")
    
f = open(testfile.py)
# opening a text file
f = open("testfile.txt","r")
for i in f:
    print(i)



# file not found erroe
try:
    f = open("samplefile.txt","r")
except FileNotFoundError:
    print("the file doesnot exist")
    

    

#the file has been overwrited

f = open("testfile.txt","r")
for i in f.readlines():
    print(i)
# writing into a file
fh = open("hello.txt","w")
fh.write("this is a file ")
fh = open("hello.txt","r")
fh.read()
#this is an os error 
try:
    tel = open("filer","r")  #--> here the os  error ocuurs 
    tel.write("hello how are you ")
    
except OSError:
    print("there is an os error")
    
except TypeError:
    print("there is an type error")
finally:
    print("there are no errors")
    
        
        
        
        


# valueerror
def checkifint():
    try:
        t = int(input("enter a num:"))
    except ValueError:
        print("This gives an value error")
    finally:
        print("hello")
    
checkifint()
def intiger():
    while True:
        try:
            p = int(input("enter a number:"))
        except:
            print("please enter an valid input!")
        else:
            print("great")
            break
        finally:
            print('done:)')
 intiger()<jupyter_output>enter a number:h
please enter an valid input!
done:)
enter a number:5
great
done:)<jupyter_text>assignment of exception handling<jupyter_code># exception handling assignment
try:
    for i in ["hello","how are you","there"]:
        print(i**2)

except TypeError:
    print("you have an error")

# ZeroDivisionError  
x = 5
y = 5
try:
    z = x/y
    print(z)
except ZeroDivisionError:
    print("you have error")
else:
    print("you have the answer above ")

    
    
def square():
    while True:
        try:
            t = int(input("Enter the number:"))
            square = (t**2)
            print(square)
            break
        except ValueError:
            print("you have the value error")
        finally:
            print("you have the output")
 square()
'''
please enter
'''<jupyter_output><empty_output><jupyter_text>MILE STONE PROJECT 2<jupyter_code>import random
suit = ("spades","club","heart","diamond")
rank = ("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":11,"queen":12,"king":13,"ace":14}
class card():
    def __init__(self,suit,rank):
        self.suit = suit
        self.rank = rank
        self.value = values[rank]
    def __str__(self): 
        return self.rank + " of " + self.suit
    
#three_clubs = card("club","three")
#three_clubs.__str__()
#print(three_clubs)
#three_clubs.value
    
        
         
class deck():
    
    def __init__(self):
        self.all_cards = []
        
        for suits in suit:
            for ranks in rank:
                
                created_card = card(suits,ranks)
                self.all_cards.append(created_card)
                
    def shuffle(self):
        random.shuffle(self.all_cards)
        
    def deal_one(self):
        return self.all_cards.pop()
                
                
                
                
#new_deck = deck()
#print(new_deck.all_cards[-1])
#new_deck.shuffle()
#print(new_deck.all_cards[0]) # randomly printed 
#new_deck.deal_one()
#print(new_deck.deal_one())


                
                 
        
        
            
         
#for card_object in new_deck.all_cards:
    #print (card_object)
class player():
    
    
    def __init__(self,name):
        self.name = name
        self.all_cards = []
        
    def remove_one(self):
        return self.all_cards.pop(0)
    
    
    def add_cards(self,new_cards):
        if type(new_cards) == type([]):
            self.all_cards.extend(new_cards)
        else:
            self.all_cards.append(new_cards)
    def __str__(self):
        return  f'player {self.name} has {len(self.all_cards)} cards'
    
#new_player  =  player("jose") # object
#print(new_player)
#new_player.add_cards(card_object)
#print(new_player)






        
        
# GAME SETUP

player_one = player("one")
player_two = player("two")

new_deck = deck()
new_deck.shuffle() 

for x in range(26):
    player_one.add_cards(new_deck.deal_one())
    player_two.add_cards(new_deck.deal_one())


#print(player_one.all_cards[0])
#len(player_one.all_cards)
game_on = True
round_num = 0

while game_on:
    round_num = round_num + 1
    print(f'round is {round_num}')
    
    if len(player_one.all_cards) == 0:
        print("player one is out of cards,player two  has won the game")
        game_on = False
        break
    if len(player_two.all_cards) == 0:
        print("player two is out of cards,player one has won the game")
        game_on = False
        break
        
    # the start of the game
    player_one_cards = []
    player_one_cards.append(player_one.remove_one())
    
    player_two_cards = []
    player_two_cards.append(player_two.remove_one())
    
    at_war = True
    
    while at_war:
        if player_one_cards[-1].value > player_two_cards[-1].value:
            
            player_one.add_cards(player_one_cards)
            player_one.add_cards(player_two_cards)
            
            at_war = False
        elif player_one_cards[-1].value < player_two_cards[-1].value:
            
            player_two.add_cards(player_two_cards)
            player_two.add_cards(player_one_cards)
            at_war = False
            
        else:
            print("at war!")
            
            if len(player_one.all_cards) < 3:
                print("player one is unable to declare war")
                print("the player two has won the game !!")
                
            if len(player_two.all_cards) < 3:
                print("player two is unable to declare war")
                print("the player one has won the game !!")
                
            else:
                for i in range(3):
                    player_one_cards.append(player_one.remove_one())
                    player_two_cards.append(player_two.remove_one())
            
            
            
            
            
    
    
    
    
import random
suit = ("spades","club","heart","diamond")
rank = ("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":11,"queen":12,"king":13,"ace":14}

class cards():
    
    def __init__(self,suit,rank):
        
        self.suit = suit
        self.rank = rank
        self.value = values[rank]
        
    def __str__(self):
        return  self.rank + " of " + self.suit
       
        
#player1 = cards("spades","three")  

class deck():
    
    def __init__(self):
        
        self.all_cards = []
        
        
        for suits in suit:
            for ranks in rank:
                
                
                created_cards = cards(suits,ranks)
                
                self.all_cards.append(created_cards)
                
                
    def shuffle(self):
        return random.shuffle(self.all_cards)
    
    
    def deal_one(self):
        return self.all_cards.pop()
    
    
class player():
    
    def __init__(self,name):
        self.name = name
        self.all_cards = []
        
    def remove_one(self):
        return self.all_cards.pop(0)
    
    def add_cards(self,new_cards):
        if type(new_cards) == type([]):
            self.all_cards.extend(new_cards)
        else:
            self.all_cards.append(new_cards)
    def __str__(self):
        return f'player {self.name} has {len(self.all_cards)} cards'
    
    
#game setup

player_1 = player("one")
player_2 = player("two")

new_deck = deck()
new_deck.shuffle()

for x in range(26):
    player_1.add_cards(new_deck.deal_one())
    player_2.add_cards(new_deck.deal_one())
    
    
game_on = True

round_num = 0

while game_on:
    round_num = round_num + 1
    print(f'round {round_num}')
          
          
    if len(player_1.all_cards) == 0:
          print("player two has won the game!")
          game_on =False
          break
    if len(player_2.all_cards) == 0:
          print("player one has won the game!")
          game_on - False
          break
          
    player_one_cards = []
    player_one_cards.append(player_1.remove_one())
    player_Two_cards = []
    player_Two_cards.append(player_2.remove_one()) 
          
          
    at_war = True
          
    if player_one_cards[-1].value > player_Two_cards[-1].value:
          
          player_1.add_cards(player_one_cards)
          player_1.add_cards(player_Two_cards)
          
    if player_one_cards[-1].value < player_Two_cards[-1].value:
          
          player_2.add_cards(player_one_cards)
          player_2.add_cards(player_Two_cards)      
    else:
          print("at war!")
          
          if len(player_1.all_cards) < 3:
                print("player one is unable to declare war")
                print("the player two has won the game !!")
          if len(player_2.all_cards) < 3:
                print("player two is unable to declare war")
                print("the player one has won the game !!")
          
          else:
                for i in range(3):
                    player_one_cards.append(player_1.remove_one())
                    player_Two_cards.append(player_2.remove_one())<jupyter_output>round 1
at war!
round 2
round 3
at war!
round 4
round 5
round 6
round 7
at war!
round 8
round 9
round 10
round 11
round 12
round 13
round 14
at war!
round 15
at war!
round 16
at war!
round 17
at war!
round 18
at war!
round 19
player two has won the game!<jupyter_text>mile stone project 3<jupyter_code>import random
suit = ("spades","club","heart","diamond")
rank = ("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":11,"queen":12,"king":13,"ace":14}

class card():
    
    def __init__(self,suit,rank):
        self.suit = suit
        self.rank = rank
        
    def __str__(self):
        return self.rank + " of " + self.suit
    





class deck():
    
    def __init__(self):
        
        self.all_cards = []
        for suits in suit:
            for ranks in rank:
                
                created_cards = card(suits,ranks)
                
                self.all_cards.append(created_cards)
                
    def __str__(self):
        deck_comp = " "
        for cards in self.all_cards:
            deck_comp += "\n" +  cards.__str__()
            
        return "The deck has: "+ deck_comp     
            
            
                
                
    def shuffle(self):
        random.shuffle(self.all_cards)
        
        
         
    
    
    def deal_one(self):
        single_card = self.all_cards.pop()
        return single_card
        
        
        
        
#test_deck = deck()
#test_deck.shuffle()
#print(test_deck)
        
        
                
                
                
                
                
                
                
            
    
    
class hand():
    
    def __init__(self):
        self.cards = []
        self.value = 0
        self.aces = 0
        
    def add_cards(self,new_cards):
        self.cards.append(new_cards)
        self.value = self.value + values[new_cards.rank]
        #track aces
        if new_cards.rank == "ace":
            self.aces = self.aces + 1
        
        
        
        
            
            
    def adjust_for_ace(self):
        
        while self.value > 21 and self.aces > 0:
            self.value = self.value - 10
            self.aces = self.aces  - 1
         
        
          
        
        
         
#test_deck = deck()

#test_deck.shuffle()

#test_player = hand()
#pulled_cards = test_deck.deal_one()
#print(pulled_cards)
#test_player.add_cards(pulled_cards)
#print(test_player.value)

        
            
        
        
        
class chips():
    
    def __init__(self,total = 100):
        self.total = total
        self.bet = 0
        
    def win_bet(self):
        self.total = self.total + self.bet
        
    def lose_bet(self):
        self.total = self.total - self.bet
        
#chips = chips()
#chips.total
         
    
    
def take_bet(chips):
    
    while True:
        
        try:
            chips.bet = int(input("enter the amount that you want to place the bet$"))
        except:
            print("sorry enter an valid input!!!!")
        if chips.bet > chips.total:
            print("you dont have enough money to play ,your balance is {}".format(chips.total))
        else:
            break
            
            
def hit(deck,hand):
    single_card = deck.deal_one()
    hand.add_cards(single_card)
    hand.adjust_for_ace()
def hit_or_stand(deck,hand):
    
    
    while True:
        x = input("enter the hit or stand? 'h' or 's' ")
        
        if x[0].lower() == "h":
            hit(deck,hand)
            
            
        elif x[0].lower() == "s" :
            print("the player like to stand ,aganist the dealers turn!")
            break
        else:
            print("please iam not able to undersatnd please enter 'h'or 's' ")
            
        
def player_busts(player,dealer,chips):
    print("player busts!!")
    chips.lose_bet()
    
def player_wins(player,dealer,chips):
    print("player wins!!")
    chips.win_bet()
    
    
def dealer_busts(player,dealer,chips):
    print("player wins,dealer busts")
    chips.win_bet()
    
def dealer_wins(player,dealer,chips):
    print("player loses,dealer wins")
    chips.lose_bet()
    
def push(player,dealer):
    print("tie between the player and the dealer!")
def show_some(player,dealer):
    
    print("Dealers hand")
    print("one card hidden")
    print(dealer.cards[1])
    print('\n')
    print("players hand")
    for card in player.cards:
        print(card)
        
def show_all(player,dealer):
    print("dealers hand")
    for card in dealer.cards:
        print(card)
        
    print('\n') 
    print("players hand")
    for card in player.cards:
        print(card)
# game on
playing  = True
while True:
    print("Welcome to the game :) ")
    
    decke = deck()
    decke.shuffle()
    
    # each player gets two cards
    player_hand = hand()
    player_hand.add_cards(decke.deal_one())
    player_hand.add_cards(decke.deal_one())
    
    dealers_hand = hand()
    dealers_hand.add_cards(decke.deal_one())
    dealers_hand.add_cards(decke.deal_one())
    
    player_chips = chips()
    take_bet(player_chips)
    
    show_some(player_hand,dealers_hand)
    
    while playing:
        hit_or_stand(decke,player_hand)
        
        show_some(player_hand,dealers_hand)
        
        if player_hand.value > 21:
            player_busts(player_hand,dealers_hand,player_chips)
            
            
            break
            
            
    if player_hand.value <= 21:
        
        
        while dealer_hand.value < 17:
            hit(decke,dealer_hand)
            
        show_all(player_hand,dealer_hand)
        
        
        if dealer_hand.value > 21:
            dealer_busts(player_hand,dealer_hand,player_chips)
            
        elif dealers_hand.value > player_hand.value:
            dealer_wins(player_hand,dealer_hand,player_chips)
            
        elif dealers_hand.value < player_hand.value:
            player_wins(player_hand,dealer_hand,player_chips)
            
        else:
            push(player_hand,dealers_hand)
            
            
        print("\n player total chips are at :{}".format(player_chips.total))  
   


  
     
            
            
            
            
            
        
        
            
            
             
            
             
            
            
              
            
            
           
        
    
    
    
    
def wri(m):
    print("hello {}".format(m))
    
t = "neeraj"    
wri(t)
def name(enter):
    
    p = " "
    for i in enter:
        p = i + p
    return(p)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11152518222173508, 'fraction_numerical': 0.010303063517290514, 'mean_word_length': 1.759413276878875, 'pattern_counts': {'":': 41, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '617634', 'license': 'Apache-2.0', 'n_tokens_mistral': 5842, 'n_tokens_neox': 5645, 'n_words': 1235, 'path': 'only python codes/udemy python 2.ipynb', 'repo_name': 'NEERAJASHISH/my-personal-codes', 'size': '18247'}