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 farenheit_to_celsius(f): | |
return ((f-32)*5/9) | |
f = 70 | |
# Was print(str(f) + 'F -> ' + '%2.1f' % (farenheit_to_celsius(f)) + 'C') # => 70F -> 21.1C | |
# Now, as per Victor's suggestion: | |
print('%2.1fF -> %2.1fC' % (f, farenheit_to_celsius(f))) # => 70.0F -> 21.1C |
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 is_a_vowel(c): | |
return c.lower() in "aeiou" | |
# or | |
def is_a_vowel(c): | |
return "aeiou".find(c.lower()) != -1 | |
# or | |
def is_a_vowel(c): | |
import re # Can be before def |
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 leap_year(y): | |
if y % 400 == 0: | |
return True | |
if y % 100 == 0: | |
return False | |
if y % 4 == 0: | |
return True | |
return False | |
# or |
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 future_value(pv, r, n): | |
return (pv * (1 + 0.01 * r) ** n) | |
pv = 100 | |
r = 0.5 | |
n = 12 | |
print("future_value(pv = {0:5.2f}, r = {1:3.2f}, n = {2:2}) = {3:5.2f}".format (pv, r, n, future_value(pv, r, n))) | |
# => future_value(pv = 100.00, r = 0.50, n = 12) = 106.17 |
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 Quick Look at Python | |
p. 5 mention parallel assignment | |
p. 6 naming convention: lower case | |
p. 8 Note how the start is always included...+ word[4:] ’Python’ | |
Should be after the following para. | |
p. 8 delete "Also remember that" before "Python strings cannot be changed - they are immutable". |
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 get_dow: | |
>>> dow = input('Enter day of week (0=Sunday, 1=Monday, ...):)' | |
>>> print ("you entered " + str(dow)) | |
>>> if Dow == 2: | |
>>> print("It's Tuesday") | |
>>> else | |
>>> | |
>>> # We won't bother | |
... # checking to see what | |
... # the day of week |
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 a(): | |
... print("a") | |
... | |
>>> a() | |
a | |
>>> | |
>>> def b(): | |
... print("b") | |
... | |
... b() |