View anagram.py
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 sys | |
from collections import defaultdict | |
import urllib2 | |
#quit if not python@2 | |
if sys.version_info >= (3, 0): | |
sys.stdout.write("Sorry, requires Python 2.x, not Python 3.x\n") | |
sys.exit(1) | |
View quicksort.py
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
def quicksort(p_list): | |
""" | |
Quicksort using comprehension and recursion on a list. | |
""" | |
if len(p_list) < 1: | |
return p_list | |
center = p_list[len(p_list) // 2] |
View product01.py
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
def pront(prompt, message): | |
print(f"{message} {input(prompt)}!") | |
pront ("Please enter your name: ", "Hello,") |
View product02.py
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
def pront(prompt, message): | |
userinput = input(prompt) | |
outputmessage = f"{message} {userinput}!" | |
print(outputmessage) | |
pront ("Please enter your name: ", "Hello,") |
View controlflow.py
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
age = input("Please tell me your age: ") | |
age = int(age) | |
if age < 21: | |
print ("No alcohol can be served to you.") | |
else: | |
print ("Which drink may I prepare for you?") |
View controlflow02.py
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
age = input("Please tell me your age: ") | |
age = int(age) | |
if age < 21: | |
print ("You may not hire a vehichle.") | |
elif age <25: | |
print ("We will add a 'young driver fee' to your rental bill.") | |
elif age < 45: | |
print ("Do you require a child seat for a small daily fee?") | |
elif age > 55: |
View truthtable.py
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
print (f"1 and 1: {bool(1 and 1)}") | |
print (f"0 and 0: {bool(0 and 0)}") | |
print (f"1 and 0: {bool(1 and 0)}") | |
print (f"not 0: {bool(not 0)}") | |
print (f"not 1: {bool(not 1)}") | |
print (f"1 or 1: {bool(1 or 1)}") | |
print (f"0 or 0: {bool(0 or 0)}") | |
print (f"1 or 0: {bool(1 or 0)}") |
View set01.py
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
students = {"Emily@gmail.com", "Harish@gmail.com", "Naomi@gmail.com", "Haru@gmail.com", "Haru@gmail.com"} | |
for student in students: | |
print (student) |
View datatypestring.py
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
#Let's define a string to begin with. | |
sentence = "The quick brown fox jumped over the lazy dog." | |
#let's show the string with all characters in lower case | |
print(f"Lower case representation:\n{ sentence.lower() }") | |
#let's show the string with all characters in title case | |
print(f"Title case representation:\n{ sentence.title() }") |
View citynames.py
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
capitals = {"London", "New York", "Kuala-Lumpur", "Den Haag", "Bern", "Peking"} | |
for city in capitals: | |
if city.find(' ') > 0: | |
print(f"This city's name is comprised of more than one word: {city}") | |
elif city.find('-') > 0: | |
print(f"This city's name is comprised of more than one word: {city}") | |
else: | |
print(f"This city's name is just one word: {city}") |
OlderNewer