This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: '); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.io.*; | |
public class FileBrowser{ | |
private static String logName; | |
public FileBrowser(){ | |
logFile(); | |
run(); |
NewerOlder