Skip to content

Instantly share code, notes, and snippets.

View davegotz's full-sized avatar

David Gotz davegotz

View GitHub Profile
@davegotz
davegotz / .block
Last active October 15, 2024 03:28
Using d3-tip with D3.js Version 4
license: cc-by-4.0
@davegotz
davegotz / .block
Last active August 19, 2020 02:17
Bar Chart I
license: gpl-3.0
@davegotz
davegotz / .block
Last active August 30, 2018 12:53
Bar Chart using SVG
license: gpl-3.0
__author__ = 'David Gotz, [email protected]'
print('Hello, World!')
@davegotz
davegotz / oil_change.py
Last active January 22, 2019 16:28
Oil Change Example
# Get the current mileage and the mileage at the last oil change.
current_mileage = int(input("Enter the current mileage: "))
last_change_mileage = int(input("Enter mileage for last oil change: "))
# Check for valid input.
if current_mileage < last_change_mileage:
# Display an error if invalid input is found.
print('The current mileage is less than the last change mileage. Please try again.')
else:
# Calculate difference in mileage
@davegotz
davegotz / playpen1.py
Created January 24, 2019 15:34
Pseudocode for higher lower
#####
# Start with player 1, who chooses the number to guess
#####
# Ask player 1 for a value between 0 and 100
#####
# Now it is time for player 2 to guess...
#####
@davegotz
davegotz / higher_lower.py
Created January 24, 2019 15:47
Final version of higher/lower
#####
# Start with player 1, who chooses the number to guess
#####
# Ask player 1 for a value between 0 and 100
target_number = int(input('Player 1: Enter a number between 0 and 100: '))
#####
# Now it is time for player 2 to guess...
#####
@davegotz
davegotz / star_patterns.py
Created January 29, 2019 15:47
Star pattern examples
# Print "size" lines where size is the size of the pattern.
size = 15
#for line in range(size): # 0, 1, 2, 3, 4
# # Print spaces (0, 1, 2, 3, 4)
# for space in range(line):
# print(' ', end='')
#
# # Print stars (5, 4, 3, 2, 1)
# for star in range(size-line):
@davegotz
davegotz / symbol_pattern.py
Created January 31, 2019 15:42
Symbol pattern with functions
# Prints the requested number of symbols without a newline.
def print_symbol(symbol, count):
for i in range(count):
print(symbol, end='')
# Draws a single line of spaces and symbols using the given size/line number.
def print_line(size, symbol, line_num):
# Print spaces
print_symbol(' ', line_num)
@davegotz
davegotz / rolling_dice.py
Created February 5, 2019 15:33
Rolling dice
import random
# Returns a random value from 1-6 with uniform distribution.
def roll():
return random.randint(1, 6)
# Simulates a pair of dice
def roll_dice():