Skip to content

Instantly share code, notes, and snippets.

View davegotz's full-sized avatar

David Gotz davegotz

View GitHub Profile
@davegotz
davegotz / student_directory.py
Created March 19, 2019 14:49
Student directory with dictionaries
# Create a student directory by allowing the user to enter all data.
def create_student_directory():
all_students_by_onyen = {}
all_students_by_email = {}
all_students_by_name = {}
# Get as many students as the user wants to enter,
# storing each in “students” onyen as key.
stud_name = input('Enter student name (enter blank line to quit): ')
while stud_name != '':
__author__ = 'David Gotz, gotz@unc.edu, Onyen = gotz'
import random
# Simulates a random card drawing. Returns a dictionary with suit and value
# keys.
def draw_card():
suit = random.choice(["Spades", "Clubs", "Diamonds", "Hearts"])
value = random.randint(1,13)
import random
MAX_NUMBER = 10
def user_picks():
user_numbers = set()
# Add six numbers to the set.
while len(user_numbers) < 6:
# Playing Card class, represents a single playing card.
class PlayingCard:
def __init__(self, value, suit):
# Setup the instance variables.
self.value = value
self.suit = suit
self.face_up = False
def main():
# Playing Card class, represents a single playing card.
class PlayingCard:
def __init__(self, value, suit):
# Setup the instance variables.
self.value = value
self.suit = suit
self.face_up = False
def get_suit(self):
return self.suit
import random
# Playing Card class, represents a single playing card.
class PlayingCard:
def __init__(self, value, suit):
# Setup the instance variables.
if value == 1:
value = 'Ace'
elif value == 11:
value = 'Jack'
import random
# Playing Card class, represents a single playing card.
class PlayingCard:
# Value should be 1-13, with 1 for Ace, 11 for Jack, etc.
def __init__(self, value, suit):
# Setup the instance variables.
self.value = value
self.suit = suit
# Get a list of names
def get_name_list():
name_list = []
name = input("Enter name #1 (or press enter to stop): ")
# Keep going until the empty string is returned by input.
while name != "":
# Append the most recent name and ask the user for the next name.
name_list.append(name.upper())
name = input("Enter name #"+str(len(name_list)+1)+" (or press enter to stop): ")
@davegotz
davegotz / blackjack_oop_day1.py
Created April 2, 2019 14:22
First day with blackjack example
import random
# Playing Card class, represents a single playing card.
class PlayingCard:
# Value should be 1-13, with 1 for Ace, 11 for Jack, etc.
def __init__(self, value, suit):
# Setup the instance variables.
self.value = value
self.suit = suit
@davegotz
davegotz / blackjack_oop_part2.py
Last active April 2, 2019 14:50
Added hand implementation and __str__ methods.
import random
# Playing Card class, represents a single playing card.
class PlayingCard:
# Value should be 1-13, with 1 for Ace, 11 for Jack, etc.
def __init__(self, value, suit):
# Setup the instance variables.
self.value = value
self.suit = suit