Skip to content

Instantly share code, notes, and snippets.

@PatchRowcester
PatchRowcester / Index.html
Created March 17, 2015 11:16
Code sample for index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Patch Rowcester</title>
</head>
<body bgcolor="black" text="#FFFF00">
@PatchRowcester
PatchRowcester / stringPalindrome.py
Created April 30, 2013 16:59
A python program that accepts a string and tells the user if the string is a palindrome
def isPalindrome(s):
def toChar(s):
s = s.lower()
ans=''
for c in s:
if c in 'abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+<>/?;:{}[]':
ans = ans+c
return ans
def isPal(s):
@PatchRowcester
PatchRowcester / gcdIter.py
Created April 23, 2013 02:32
Iterative way to calculate the GCD of two numbers.
def gcdIter(a,b):
x = min(a,b)
for i in range(min(a,b)):
if a%x==0 and b%x==0:
break
else:
x -= 1
return x
print('This is a program to calculate the GCD of two integers.')
a = int(raw_input('Enter first number: '))
@PatchRowcester
PatchRowcester / recursivePower.py
Created April 19, 2013 03:10
A recursive function to calculate the exponential of a base number by checking if the exponential is even, odd or equal to 0
def recurPowerNew(base, exp):
'''
base: int or float.
exp: int >= 0
returns: int or float; base^exp
'''
# Your code here
if exp<=0:
return 1
@PatchRowcester
PatchRowcester / bisection_payment.py
Last active December 16, 2015 06:29
Python program that will calculate the minimum monthly payment to finish paying a loan in 12 months, using bisection search.
balance = float(raw_input('Enter the balance: '))
annualInterestRate = float(raw_input('Enter the annual interest rate (decimal): '))
##defining the variables
monthlyInterestRate = annualInterestRate/12.0
##Lowest payment will not be lower than balance/12
low = balance/12.0
@PatchRowcester
PatchRowcester / fixed_min_payment.py
Created April 10, 2013 01:23
Program that will accept an initial balance, and annual interest and output the lowest payment (multiple of 10), that is needed to pay off the balance in 12 months.
balance = float(raw_input("Enter the total balance: "))
annualInterestRate = float(raw_input("Enter the annual interest rate (decimal): "))
monthlyInterestRate = annualInterestRate/12.0
initialPayment = 0
totalPaid = 0
while True:
initialPayment += 10
tempBalance = balance
for i in range(1,13):
@PatchRowcester
PatchRowcester / MonthlyPayments.py
Created April 3, 2013 01:07
This program will accept values of balance, annual interest rate and monthly payment rate, and calculate the monthly interest rate, minimum monthly payment and remaining balance for 12 months. After this, it will print out the total amount paid, and the remaining balance at the end of 12 months.
balance = float(raw_input("Enter the outstanding balance: "))
annualInterestRate = float(raw_input("Enter annual interesst rate (decimal): "))
monthlyPaymentRate = float(raw_input("Enter monthly payment rate (decimal): "))
monthlyInterestRate = annualInterestRate/12.0
totalPaid = 0
for i in range(1,13):
minMonthlyPayment = monthlyPaymentRate * balance
print("Month: " + str(i))
print("Minimum monthly payment: " + str(round(minMonthlyPayment,2)))
@PatchRowcester
PatchRowcester / isVowel.py
Created March 26, 2013 03:51
Program to that will accept a string and return True if the string is a single character vowel of any case. False if not.
def isVowel(char):
'''
char: a single letter of any case
returns: True if char is a vowel and False otherwise.
'''
# Your code here
if ((char =='a') or (char=='e') or (char == 'i') or (char == 'o') or (char =='u')):
return True
elif ((char =='A') or (char=='E') or (char == 'I') or (char == 'O') or (char =='U')):
@PatchRowcester
PatchRowcester / odd.py
Created March 26, 2013 03:40
A program to accept a number, and return True if it is odd, and False if it is even without using IF keyword
def odd(x):
'''
x: int or float.
returns: True if x is odd, False otherwise
'''
# Your code here
y = x%2
return bool(y)
@PatchRowcester
PatchRowcester / clip.py
Created March 20, 2013 02:17
Takes in three numbers and returns a value based on the value of x. Returns: - lo, when x < lo - hi, when x > hi - x, otherwise
def clip(lo, x, hi):
'''
Takes in three numbers and returns a value based on the value of x.
Returns:
- lo, when x < lo
- hi, when x > hi
- x, otherwise
'''
# Your code here
return min(max(x,lo),hi)