Skip to content

Instantly share code, notes, and snippets.

@jacks205
jacks205 / StringFunctions.py
Created May 14, 2013 05:40
String Functions contains a group of random string methods.
# Generate a string with all letters from the English alphabet. :
def alphabet():
result = 'abcdefghijklmnopqrstuvwxyz';
return result + result.upper();
# Generate a randomly scrambled version of a string:
import random;
def scramble(string):
characterList = list(string);
random.shuffle(characterList);
@jacks205
jacks205 / ScoreFiler.py
Created May 14, 2013 05:39
Score Filer takes the scores of a test and returns the Average, Lowest, and Highest score(s) of the test.
# Input student records from a file and return a list of records:
def read(fileName):
listOfStudents = [];
inFile = open(fileName, 'rU'); # read in "universal end-of-line" mode
for line in inFile:
# Strip unnecessary '\n' from right end:
line = line.rstrip('\n');
student = line.split(',');
# student = ['last-name', 'first-name', 'score']
listOfStudents.append(student);
@jacks205
jacks205 / StockTracker.py
Created May 14, 2013 05:38
Stock tracker that takes information from Yahoo Stocks and prints it to the screen, and then updates it continuously.
import urllib;
# Stock checkup - Download and display a stock quote:
def checkup(symbol):
keywords = ['Symbol', 'Price', 'Open', 'Date', 'Time', 'Volume'];
stock = getStock(symbol, keywords);
display(stock);
# Display stock quote from a dictionary:
def display(stock):
@jacks205
jacks205 / Hangman.py
Created May 14, 2013 05:35
Hangman Simulation. Takes words out of a words.txt file.
import random;
# Repeatedly play the game of Hangman:
def play():
maxAllowedAttempts = 8;
print rulesDisplay(maxAllowedAttempts);
listOfWords = inputListOfWords('words.txt');
while (True):
playOneGame(maxAllowedAttempts, listOfWords);
ans = inputYesNo('\nPlay more? [Yes/No]: ');
@jacks205
jacks205 / Card.java
Last active December 17, 2015 07:38
A simulation of the card game "War." You enter the amount of games you want to simulate and it will give you: Average Wars, Average Double Wars, Average Battles, Max/Min Battles per game, Max/Min Wars per game, Max/Min Double Wars per game Uses LinkedLists to keep track of decks and exchanges of cards.
public class Card {
private int value; //didnt include suit because it messed with calculations (not important for the War game, but in the future I will try to include things like that for reuse-ability)
public Card(int i){
value = i;
}
public int getCardValue(){
return value;
@jacks205
jacks205 / FileBrowser.java
Last active December 17, 2015 07:38
This is a File Browser program that can be used to locate, append, and display files, also has an option of creating a log file that updates and prints everything that is shown to the user. Option (4) is the one thing I can't get working at the moment but it doesn't crash the program.
import java.util.Scanner;
import java.io.*;
public class FileBrowser{
private static String logName;
public FileBrowser(){
logFile();
run();