Skip to content

Instantly share code, notes, and snippets.

@BornRiot
BornRiot / Hand.py
Created November 16, 2020 00:45
Resolution for Implement an adjust for Aces method. #84
class Hand:
def __init__(self, name):
self.name = name
self.cards = [] # start with an empty list as we did in the Deck class
self.value = 0 # start with zero value
self.aces = 0 # add an attribute to keep track of aces
def add_card(self,card):
# Code Implementation solves the issue with
@BornRiot
BornRiot / war_game_final.py
Last active October 14, 2020 01:57
Computer Vs Computer version of the card game war.
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import random
# Creation of the card class should include the following properties: Suit, Rank, Value
values = {'Two':2,'Three':3,'Four':4,'Five':5,'Six':6,'Seven':7,'Eight':8,'Nine':9,'Ten':9,'Jack':11,
'Queen':12,'King':13,'Ace':14}
@BornRiot
BornRiot / decorators_overview.py
Created September 14, 2020 01:49
Program that give examples of Python Decorators
"""
This module documents the definition and how to use
decorators in a python program.
"""
# Python has decorators which allow users to tack on extra functionality
# to an already existing function. It uses the @ operator to do so.
# manually buidling out a decorator function:
def func():
return 1
@BornRiot
BornRiot / table_idea.py
Created July 16, 2020 11:59
My Solution for a tic-tac-toe table
the_table = list()
the_table.append('X')
the_table.append('X')
the_table.append('X')
the_table.append('X')
the_table.append('X')
the_table.append('X')
the_table.append('X')
the_table.append('X')
"""module docstring"""
from collections import Counter
SAMPLE_STRING = 'Hello Mr. Rogers, how are you this fine Tuesday?'
def count_upper(sentence):
"""Function docstring"""
split_string = sentence.split(" ")
for item in split_string:
if item[0].isupper():
@BornRiot
BornRiot / get_primes.py
Created June 21, 2020 22:10
Program to get prime number in an interval
start = 11
end = 25
for val in range(start, end + 1):
if val > 1:
for n in range(2, val//2 + 2):
if (val % n) == 0:
break
else:
if n == val//2 + 1:
@BornRiot
BornRiot / Find_Index.py
Created June 5, 2020 14:50
Find index of element in a list
#Example 1: Find the index of the element in vowels
vowels = ['a', 'e', 'i', 'o', 'i', 'u']
# index of 'e' in vowels index =
vowels.index('e') print('The index of e:', index)
# element 'i' is searched # index of the first 'i' is returned index = vowels.index('i') print('The index of i:', index)
@BornRiot
BornRiot / ListCommonElements.py
Created May 27, 2020 20:14
function used to check common element in two list
def common_member(a,b):
a_set = set(a)
b_set = set(b)
if len(a_set.intersection(b_set)) > 0:
return a_set.intersection(b_set)
else:
return "No common elements"
a = [1,5,9,8,4,5,7]
b = [3,14,8,7,9,87,58,5,6]
@BornRiot
BornRiot / CompareTwoList.py
Last active June 19, 2020 19:31
Code for comparing two list element wise
# Website with more info https://bit.ly/3d5WMoR
#List have to be same length
first= (1,2,3,4,5,6)
last=(6,5,4,3,2,1)
for i in range(len(first)):
l1 = first[i]
l2 = last[i]
if l1 < l2:
print("l1 < l2")
elif l1 > l2:
public class BarkingDog{
public static void main(String[] args) {
boolean theResult = shouldWakeUp(false, 2);
System.out.println(theResult);
}
public static boolean shouldWakeUp(boolean barking, int hourOfDay){
boolean wakeUp = false;
barking = false;
if ( hourOfDay >= 0 && hourOfDay <= 7){ //Sleeping after midnight
if (barking = true){