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 function named distance_between_points() | |
# that takes 2 Point as argument | |
# and return the distance between them | |
import math | |
class Point: """ a 2D point """ | |
a = Point() | |
a.x = 0.0 |
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 function that reads words in words.txt and ... | |
store them in a dictionary | |
Use the in operator as a fast way to check | |
Compare the speed of impelemtation with the bisection search | |
https://github.com/AllenDowney/ThinkPython2/blob/master/code/words.txt | |
https://gist.github.com/minte9/4c411d0c83cfdfa718085f792f810a18 """ |
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
# Make a Bisection Search (or binary search), | |
# similar to what you do in dictionary. | |
# You start in the middle of the list, then you search the second half | |
# https://github.com/AllenDowney/ThinkPython2/blob/master/code/words.txt | |
# Word List | |
words = [] | |
for line in open("/var/www/python/words.txt"): |
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
# Get the words with three consecutive double letters | |
# https://github.com/AllenDowney/ThinkPython2/blob/master/code/words.txt | |
def has3_2consecutive(word): | |
i = 0; count = 0 | |
while i < len(word) - 1: | |
if word[i] == word[i+1]: | |
count = count + 1 | |
if count == 3: | |
return True |
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
# A Caesar cypher is a weak form on encryption | |
# It involves "rotating" each letter by a number (shift it through the alphabet) | |
# A rotated by 3 is D; Z rotated by 1 is A | |
# In a SF movie the computer is called HAL, which is IBM rotated by -1 | |
# Write a function rotate_word() | |
# Use built-in functions ord (char to code_number), chr (codes to char) | |
# SOLUTION |
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 function called is_palindrom | |
# You can use built-in funciton len to check the string length | |
# A palindorm is a word that is spelled the same backward and forward | |
# Example: noon, redivider | |
def first(word): return word[0] | |
def last(word): return word[-1] | |
def middle(word): return word[1:-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
# Use incremental development to write a function called hypotenuse | |
# The function returns the length of the hypotenuse of a right triangle | |
# The function gets the other two legs as arguments | |
# Record each stage of the development | |
# SOLUTION | |
# v1.0 -------------------------- | |
def hypotenuse(a, b): | |
return 0 |
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
""" | |
There are no positive integers a, b, c so that | |
a**n + b**n = c**n for any number > 2 (Fermat Last Theorem) | |
-------------------------------------------------------------- | |
Define a function prompt_user() that ask user | |
to input values for a, b, c and n and converts them to ingeters | |
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 function convert() that returns | |
# days, hours, minutes, seconds since UTC | |
# The time module provides a function, also named time, | |
# that returns the current GMT in “the epoch” | |
import time | |
today = time.time() | |
# SOLUTION |
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 function called circle that takes a turtle, t, and radius, r, | |
as parameters and that draws an approximate circle | |
by calling polygon with an appropriate length and number of sides. | |
Test your function with a range of values of r. | |
Hint: figure out the circumference of the circle | |
and make sure that length * n = circumference. |
NewerOlder