This file contains hidden or 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
| def median(some_list): | |
| x = sorted(some_list) | |
| if len(x)%2 == 0: | |
| q = len(x)/2 | |
| t = x[q] | |
| u = x[(q-1)] | |
| v = (t+u)/2.0 | |
| return v | |
| else: | |
| w = (len(x)/2)+.5 |
This file contains hidden or 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
| def test_prime(x): | |
| if x <2: | |
| print False | |
| elif x == 2: | |
| print True | |
| # maybe i'm being lazy but i couldn't think of a way to make 2 return as prime w/o doing this. | |
| else: | |
| for i in range(2,x-1): | |
| y = x%i | |
| if y > 0: |
This file contains hidden or 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
| from random import randint | |
| board = [] | |
| for x in range(0, 5): | |
| board.append(["O"] * 5) | |
| def print_board(board): | |
| for row in board: | |
| print " ".join(row) |
This file contains hidden or 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
| s = "A bird in the hand..." | |
| # Add your for loop | |
| for x in s: | |
| if x == "A" or x == "a": | |
| print "X", | |
| else: | |
| print x, |
This file contains hidden or 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
| n = [3,5,7] | |
| def myFun(x): | |
| z = [] | |
| for i in x: | |
| z.append(i*2) | |
| print z | |
| myFun(n) |
This file contains hidden or 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
| prices = {"banana" : 4, "apple" : 2, "orange" : 1.5, "pear" : 3} | |
| stock = {"banana":6, "apple": 0, "orange": 32, "pear" : 15} | |
| for z in prices: | |
| print z | |
| print "prices: "+ str(prices[z]) | |
| print "stock: "+ str(stock[z]) | |
This file contains hidden or 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
| def hotel_cost(nights): | |
| return nights * 140 | |
| bill = hotel_cost(5) | |
| def get_min(balance, rate): | |
| return balance * rate | |
| print get_min(bill,.02) |
This file contains hidden or 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
| pyg = 'ay' | |
| original = raw_input('Enter a word:') | |
| if len(original) > 0 and original.isalpha(): | |
| word = original.lower() | |
| first = word[0] | |
| if first == "a" or "e" or "i" or "o" or "u": | |
| print "vowel" | |
| else: |
NewerOlder