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: a number | |
# Output : the next higher number that uses the same set of digits. | |
from itertools import permutations | |
def nextHighest(num): | |
"""This function takes a number as a string, finds all permutations of that number, | |
and then returns the next highest value using those digits.""" | |
if len(num) == 1: | |
return num+num | |
normal = [] |
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
#create a program that will find all prime numbers below 2000 | |
primeNumbers = [] | |
for num in range(1, 2000): | |
x = num | |
count = 0 | |
while x > 0: | |
if num %x == 0: | |
count += 1 | |
x -= 1 |
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
#Write a program that counts the number of alphanumeric characters there are in The | |
# Adventures of Sherlock Holmes. Exclude the Project Gutenberg header and footer, book | |
# title, story titles, and chapters. Post your code and the alphanumeric character count. | |
loop = True | |
charCount = 0 | |
numCount = 0 | |
# Creating reference lists for characters to count. | |
charList = 'abcdefghijklmnopqrstuvwxyxABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
numList = '1234567890' | |
# Creating start and end strings to keep the meat of the file that we will be counting |
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
#Often times in commercials, phone numbers contain letters so that they're easy to | |
# remember (e.g. 1-800-VERIZON). Write a program that will convert a phone number that | |
# contains letters into a phone number with only numbers and the appropriate dash. Click | |
# here to learn more about the telephone keypad. | |
print "This program will convert numbers with letters into the digits they represent." | |
phone = raw_input("Please enter a 1-800 number: ") | |
phone = phone.upper() | |
converter = {'A':'2', 'B':'2', 'C':'2', 'D':'3', 'E':'3', 'F':'3', | |
'G':'4', 'H':'4', 'I':'4', 'J':'5', 'K':'5', 'L':'5', | |
'M':'6', 'N':'6','O':'6', 'P':'7', 'Q':'7', 'R':'7', |
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
#Write an application which will print a triangle of stars of user-specified height, with each line having | |
#twice as many stars as the last. | |
def triangler(char, height): | |
"""assumes that char is a single character, and height is an integer between 1 - 10. | |
Uses the height int to build a triangle on the screen.""" | |
upChar = "" | |
for c in range(0, height): | |
upChar = upChar + char | |
char = upChar |
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
# coding=utf-8 | |
# Write a function that takes two strings and removes from the first string any | |
# character that appears in the second string. For instance, if the first string is “Daily Programmer” | |
# and the second string is “aeiou ” the result is “DlyPrgrmmr”. | |
# note: the second string has [space] so the space between "Daily Programmer" is removed | |
def newString(str1, str2): | |
"""Takes two strings and returns a new string with letters of the first removed from the second""" | |
result = [] | |
for i in str1: |
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
#write a program to right, or left justify text in a file. | |
start = False | |
f = open('chuckles.txt', 'r+') | |
test = f.readlines() #creating a copy of the file for looping while modifying the original file. | |
for line in test: | |
scoop = line.rjust(50) | |
if not start: # puts block at the top of the file to overwrite the existing text | |
f.seek(0) | |
start = True | |
f.writelines(scoop) |
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
#find the number of the year for the given date. For example, January 1st | |
#would be 1, and december 31st is 365 | |
import datetime | |
loop = True | |
print "We are going to figure out what day number you chose based on the date you input." | |
while loop: | |
year = input('Enter a year (YYYY): ') | |
month = input('Enter a month (MM): ') |
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 datetime | |
Days = ['Monday', 'Tuesday', 'Wedneday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] | |
loop = True | |
print "Welcome to the magical emporium of fun!" | |
print "Give me your birth date, and I will tell you what day of the week you were born on." | |
while loop: | |
year = input('Enter your birth year (YYYY): ') | |
month = input('Enter your birth month (MM): ') |
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
#The exercise today asks you to validate a telephone number, as if written on an input form. Telephone numbers can be written as ten digits, or with dashes, spaces, or dots between the three segments, or with the area code parenthesized; both the area code and any white space between segments are optional. | |
#Thus, all of the following are valid telephone numbers: 1234567890, 123-456-7890, 123.456.7890, (123)456-7890, (123) 456-7890 (note the white space following the area code), and 456-7890. | |
#The following are not valid telephone numbers: 123-45-6789, 123:4567890, and 123/456-7890. | |
import re | |
phoneNum = raw_input("Please enter a phone number: ") | |
matchObj = re.match( r'^([1]?)([\(\/\. ]?)[2-9][\d]{2}([\.\- \)]?)[2-9][\d][\d][/\.\- ]?[\d]{4}$', phoneNum) | |
if matchObj: | |
print "Great! you gave me a good phone number: %s" % phoneNum | |
else: | |
print "You should try again that phone number sucked!" |