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 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] |
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
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) | |
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 pront(prompt, message): | |
print(f"{message} {input(prompt)}!") | |
pront ("Please enter your name: ", "Hello,") |
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 pront(prompt, message): | |
userinput = input(prompt) | |
outputmessage = f"{message} {userinput}!" | |
print(outputmessage) | |
pront ("Please enter your name: ", "Hello,") |
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 geolocation(landmark): | |
if landmark == "Eiffel": | |
return 48.858093, 2.294694 | |
elif landmark == "Statue": | |
return 40.689247, -74.044502 | |
elif landmark == "Opera": | |
return -33.858611, 151.214167 | |
else: | |
return 0, 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
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?") |
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
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: |
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
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)}") |
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
students = {"[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"} | |
for student in students: | |
print (student) |
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
#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() }") |
OlderNewer