stuff to do
This commit is contained in:
commit
bc46c80b02
26
01-title_case/README.md
Normal file
26
01-title_case/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
Title Transform
|
||||
===============
|
||||
|
||||
Write a function that transforms a string into [title case](http://en.wikipedia.org/wiki/Letter_case#Headings_and_publication_titles).
|
||||
|
||||
This mostly means capitalizing only every first letter of every word in the string.
|
||||
|
||||
However, there are some non-obvious exceptions to title case which can't easily be hard-coded. Your function must accept, as a second argument, a set or list of words that should not be capitalized.
|
||||
|
||||
Furthermore, the first word of every title should always have a capital leter. For example:
|
||||
```python
|
||||
exceptions = ['jumps', 'the', 'over']
|
||||
titlecase('the quick brown fox jumps over the lazy dog', exceptions)
|
||||
```
|
||||
This should return:
|
||||
|
||||
The Quick Brown Fox jumps over the Lazy Dog
|
||||
|
||||
An example from the Wikipedia page:
|
||||
```python
|
||||
exceptions = ['are', 'is', 'in', 'your', 'my']
|
||||
titlecase('THE vitamins ARE IN my fresh CALIFORNIA raisins', exceptions)
|
||||
```
|
||||
Returns:
|
||||
|
||||
The Vitamins are in my Fresh California Raisins
|
15
01-title_case/title.py
Executable file
15
01-title_case/title.py
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
def titlecase( string, exceptions ):
|
||||
word_list = string.lower().split(' ')
|
||||
|
||||
for i, word in enumerate( word_list ):
|
||||
if( word not in exceptions ):
|
||||
word_list[i] = word.title()
|
||||
|
||||
word_list[0] = word_list[0].title()
|
||||
|
||||
return ' '.join( word_list )
|
||||
|
||||
assert( titlecase( 'the quick brown fox jumps over the lazy dog', ['jumps', 'the', 'over'] ) == 'The Quick Brown Fox jumps over the Lazy Dog' )
|
||||
assert( titlecase( 'THE vitamins ARE IN my fresh CALIFORNIA raisins', ['are', 'is', 'in', 'your', 'my'] ) == 'The Vitamins are in my Fresh California Raisins' )
|
18
02-currency/README.md
Normal file
18
02-currency/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
Float to Currency
|
||||
==================
|
||||
|
||||
Write a method that gives the number of American coins and bills needed to represent that number (rounded to the nearest 1/100, i.e. the nearest penny).
|
||||
|
||||
As an exmaple, if the float is 12.33, the result would be 1 $10, 2 $1 bills, 1 quarter, 1 nickel and 3 pennies.
|
||||
|
||||
Use the following as denominations for your currencies:
|
||||
|
||||
Penny: 1 cent
|
||||
Nickel: 5 cent
|
||||
Dime: 10 cent
|
||||
Quarter: 25 cent
|
||||
One-dollar bill
|
||||
Five-dollar bill
|
||||
Ten-dollar bill
|
||||
Fifty-dollar bill
|
||||
Hundred-dollar bill
|
35
02-currency/currency.py
Normal file
35
02-currency/currency.py
Normal file
@ -0,0 +1,35 @@
|
||||
denominations_USD = [
|
||||
{ 'title': 'Hundred-dollar bill', 'count': 0, 'val': 10000 },
|
||||
{ 'title': 'Fifty-dollar bill', 'count': 0, 'val': 5000 },
|
||||
{ 'title': 'Ten-dollar bill', 'count': 0, 'val': 1000 },
|
||||
{ 'title': 'Five-dollar bill', 'count': 0, 'val': 500 },
|
||||
{ 'title': 'One-dollar bill', 'count': 0, 'val': 100 },
|
||||
{ 'title': 'Quarter', 'count': 0, 'val': 25 },
|
||||
{ 'title': 'Dime', 'count': 0, 'val': 10 },
|
||||
{ 'title': 'Nickel', 'count': 0, 'val': 5 },
|
||||
{ 'title': 'penny', 'count': 0, 'val': 1 }
|
||||
]
|
||||
|
||||
def currency_converter( amount=0, units=[] ):
|
||||
amount *= 100
|
||||
|
||||
for unit in units:
|
||||
while( amount != 0 and amount >= unit['val'] ):
|
||||
amount -= unit['val']
|
||||
unit['count'] += 1
|
||||
|
||||
return units
|
||||
|
||||
def currency_display( amount=0, units=denominations_USD ):
|
||||
units = currency_converter( amount , units )
|
||||
|
||||
for unit in units:
|
||||
if unit['count'] == 0: continue
|
||||
|
||||
t = [ unit['count'], unit['title'], '\'s' if unit['count'] > 1 else '' ]
|
||||
print( '{} {}{}'.format(*t) )
|
||||
|
||||
return None
|
||||
|
||||
currency_amount = float( input('Convert: ') )
|
||||
currency_display( currency_amount )
|
16
03-roman-numerals/README.md
Normal file
16
03-roman-numerals/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
Arabic to Roman Numerals Challenge
|
||||
==================================
|
||||
|
||||
Did you know our numeral system - the symbols we use to represent numbers are called
|
||||
Arabic numerals? Fun fact, because now it gets serious. You're going to be translating Arabic to Italian.
|
||||
|
||||
Have the input form accept a number from the user. When the form is submitted, have the function to_roman take an integer as an argument and return a roman numerals string. For example:
|
||||
```
|
||||
60 >> LX
|
||||
78 >> LXXVIII
|
||||
99 >> XCIX
|
||||
3000 >>> MMM
|
||||
```
|
||||
Look up Roman Numerals to get a complete list and jog your memory on its ancient conventions. This is an easy challenge to code, but can be a difficult mental exercise. Don't overcomplicate it!
|
||||
|
||||
Add your own assert statements to the bottom to test your code.
|
BIN
03-roman-numerals/__pycache__/roman.cpython-34.pyc
Normal file
BIN
03-roman-numerals/__pycache__/roman.cpython-34.pyc
Normal file
Binary file not shown.
18
03-roman-numerals/roman.py
Normal file
18
03-roman-numerals/roman.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Use this function to get and return all the prime numbers below the input number
|
||||
|
||||
def to_roman(num):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
assert to_roman(11) == "XI", "11 should return XI"
|
||||
assert to_roman(60) == "LX", "60 should return LX"
|
||||
assert to_roman(78) == "LXXVIII", "78 should return LXXVIII"
|
||||
assert to_roman(4) == "IV", "4 should return IV"
|
||||
assert to_roman(99) == "XCIX", "99 should return XCIX"
|
||||
|
||||
# Add your own assert tests below
|
28
04-matrix-sort/README.md
Normal file
28
04-matrix-sort/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
Row and Column Sorting
|
||||
========================
|
||||
|
||||
Write a program that reads a matrix of numbers separated by newlines and whitespace, like this:
|
||||
|
||||
10 5 4 20
|
||||
9 33 27 16
|
||||
11 6 55 3
|
||||
|
||||
then calculates the sums for each row and column. For our example above:
|
||||
|
||||
Row Sums: 39 85 75
|
||||
Column Sums: 30 44 86 39
|
||||
|
||||
then prints two new matrices, one where the rows are sorted by their sums (ascending from top to bottom) and one where the columns are sorted by their sums (ascending from left to right). The correct output from the example above:
|
||||
|
||||
10 5 4 20
|
||||
11 6 55 3
|
||||
9 33 27 16
|
||||
|
||||
10 20 5 4
|
||||
9 16 33 27
|
||||
11 3 6 55
|
||||
|
||||
|
||||
Find the large input matrix to import and test your program on inside `testmatrix.txt`.
|
||||
|
||||
For bonus points, format your output matrices nicely (align the columns, draw boxes with - and |...)
|
0
04-matrix-sort/row_col_sort.py
Normal file
0
04-matrix-sort/row_col_sort.py
Normal file
54
05-caesar-cipher/README.md
Normal file
54
05-caesar-cipher/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
Caesar's Cipher
|
||||
================
|
||||
|
||||
[Caesar's Cipher](http://en.wikipedia.org/wiki/Caesar_cipher) is named after Julius Caesar, who used it with a shift of three to protect messages of military significance.
|
||||
|
||||
A shift of three to the right would change the letters thusly:
|
||||
|
||||
A => D
|
||||
B => E
|
||||
C => F
|
||||
...
|
||||
Z => C
|
||||
|
||||
A shift of three to the left would change the letters...
|
||||
|
||||
A => X
|
||||
B => Y
|
||||
C => Z
|
||||
D => A
|
||||
...
|
||||
|
||||
Of course this offers no communication security whatsoever - except in Roman times when most people couldn't read to begin with.
|
||||
|
||||
But the Caesar Cipher is [still used](http://en.wikipedia.org/wiki/ROT13) in cryptography, in addition to many other methods. So this is your first step into the world of security and data encryption.
|
||||
|
||||
To understand how to complete this challenge, you must first understand the [ASCII](http://en.wikipedia.org/wiki/ASCII) standard. In short, every key on your keyboard has an [assigned numeric value](http://www.asciitable.com/).
|
||||
|
||||
In Python, we use the following methods to get the ASCII decimal value.
|
||||
```python
|
||||
ord('a') # => 97
|
||||
ord('A') # => 65
|
||||
ord('x') # => 120
|
||||
```
|
||||
|
||||
To get the ASCII character from an integer, we use the `chr` function.
|
||||
```python
|
||||
chr(97) # => 'a'
|
||||
chr(65) # => 'A'
|
||||
chr(32) # => ' ' (Yes that's an empty space, it has a value too!)
|
||||
```
|
||||
|
||||
#### Round 1
|
||||
|
||||
Write the `caesar` function that takes a message and a shifted number as input and returns the shifted message.
|
||||
|
||||
#### Round 2
|
||||
Make sure you ignore spaces, symbols, and numbers. The end user wants to see these characters unchanged in the encrypted cipher. Capital letters should remain capital, and lower case letters should remain lower case.
|
||||
|
||||
#### Round 3
|
||||
Create a new decrypt function. Take an already encrypted string, and the shift number, and decrypt it back to English.
|
||||
|
||||
#### Round 4
|
||||
|
||||
Using Python's `assert` write at least 6 tests to test your code output.
|
9
05-caesar-cipher/caesar.py
Normal file
9
05-caesar-cipher/caesar.py
Normal file
@ -0,0 +1,9 @@
|
||||
def caesar(message, shift):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Add your own assert statements to test your code.
|
Loading…
x
Reference in New Issue
Block a user