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 August 30, 2018 12:53
Bar Chart using SVG
license: gpl-3.0
__author__ = 'David Gotz, gotz@unc.edu'
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():
@davegotz
davegotz / forecast.py
Created February 7, 2019 15:30
Snow or rain or dry?
# Get the chance of precipitation
def get_chance_of_precip():
# Read in precip chance as a float between 0 and 1.
precip = -1
while precip < 0 or precip > 1:
# Read in the chance of precip from the user.
precip = float(input("What is the chance of precipitation [0.0-1.0]:"))
return precip
@davegotz
davegotz / homeprices.py
Created February 7, 2019 15:48
Comparing price of a home to comps
def get_info_about_house_to_buy():
bathrooms = int(input("Enter the number of baths: "))
bedrooms = int(input("Enter the number of beds: "))
return bedrooms, bathrooms
def get_comps(beds, baths):
return 0, 0