Skip to content

Instantly share code, notes, and snippets.

@solen003
solen003 / blackjack.py
Created August 7, 2018 21:03
blackjack
suits = ('Hearts', 'Diamonds', 'Clubs', 'Spades')
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}
import random
def prepare_deck():
a_deck = []
for s in suits:
for r in ranks:
@solen003
solen003 / bankaccount.py
Created August 7, 2018 10:52
bankaccount.py
class Account():
def __init__(self, owner, balance=0):
self.owner = owner
self.balance = balance
def deposit(self, deposit_amt):
self.balance += deposit_amt
print(f'Hello {self.owner}')
print(f'Deposit of {deposit_amt} processed')
@solen003
solen003 / xo.py
Last active August 7, 2018 07:31
tic tac toe
import random
def display_board(a_board):
print(a_board[7] + '|' + a_board[8] + '|' + a_board[9])
print('-'*5)
print(a_board[4] + '|' + a_board[5] + '|' + a_board[6])
print('-'*5)
print(a_board[1] + '|' + a_board[2] + '|' + a_board[3])
def count_primes(n):
import math
primes_count = 0
for i in range(1, n+1, 2):
if i == 1:
pass
if i == 2:
def summer_69(mylist):
total = 0
add_on = True
for i in mylist:
if i == 9 and add_on == False:
add_on = True
elif i == 6:
def has_33(mylist):
for i in range(len(mylist)-1):
if mylist[i] == 3 and mylist[i+1] == 3:
return True
return False
@solen003
solen003 / aBcDeFgH.py
Last active August 6, 2018 11:05
aBcDeFgH
def myfunc(mystring):
templist = [x.lower() for x in mystring]
indx = 1
for i in templist[1::2]:
templist[indx] = i.upper()
indx += 2
return ('').join(templist)
@solen003
solen003 / word_count_sort_dictionary
Created July 18, 2018 09:43
Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically. Suppose the following input is supplied to the program: New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3. Then, the output should be: 2:2 3.:1 3?:1 New:1 Python:5 Read:1 and:1 be…
import operator
text_line = input("Type in: ")
freq_dict = {}
for i in text_line.split(' '):
if i.isalpha():
if i not in freq_dict:
freq_dict[i] = 1
@solen003
solen003 / robot.py
Created July 18, 2018 08:58
A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following: UP 5 DOWN 3 LEFT 3 RIGHT 2 ¡­ The numbers after the direction are steps. Please write a program to compute the distance from current position after a sequen…
import math
x, y = 0, 0
while True:
step = input("Type in UP/DOWN/LEFT/RIGHT #step number: ")
if step == "":
break
@solen003
solen003 / divBy7
Created July 17, 2018 22:32
Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n.
n = int(input())
divBy7 = [i for i in range(0, n) if (i % 7 == 0)]
print(divBy7)
def divChecker(n):
for i in range(n):
if i % 7 == 0:
value = True
else:
value = False