Permalink
Browse files

adding exercises

  • Loading branch information...
aspittel committed Oct 30, 2017
0 parents commit f4530a5c076e685451a8c221d1628d93a07628c2
Showing with 243 additions and 0 deletions.
  1. 0 app.py
  2. +97 −0 data-collections.md
  3. +142 −0 data-types.md
  4. +4 −0 readme.md
0 app.py
No changes.
@@ -0,0 +1,97 @@
### Arrays
Starting with the following array...
```py
planeteers = ["Earth", "Wind", "Captain Planet", "Fire", "Water"]
```
Access the second value in `planeteers`.
```py
# Your answer here
```
Add "Heart" to the end of `planeteers`.
```py
# Your answer here
```
Remove "Captain Planet" from the array.
```py
# Your answer here
```
Combine `planeteers` with `rangers = ["Red", "Blue", "Pink", "Yellow", "Black"]` and save the result in a variable called `heroes`.
```py
# Your answer here
```
Alphabetize the contents of `heroes` using a function.
```py
# Your answer here
```
Randomize the contents of `heroes` using a function. [The Python documentation might help](https://docs.python.org/2/library/random.html).
```py
# Your answer here
```
#### Bonus
Select a random element from `heroes` using a function. [The Python documentation might help](https://docs.python.org/2/library/random.html).
```py
# Your answer here
```
### Hashes
Initialize a hash called `ninja_turtle` with the properties `name`, `weapon` and `radical`. They should have values of "Michelangelo", "Nunchuks" and `true` respectively.
```py
# Your answer here
```
Add a key `age` to `ninja_turtle`. Set it to whatever numerical value you'd like.
```py
# Your answer here
```
Remove the `radical` key-value pair from `ninja_turtle`.
```py
# Your answer here
```
Add a key `pizza_toppings` to `ninja_turtle`. Set it to an array of strings (e.g., `["cheese", "pepperoni", "peppers"]`).
```py
# Your answer here
```
Access the first element of `pizza_toppings`.
```py
# Your answer here
```
Produce an list containing all of `ninja_turtle`'s keys using a function. [The Python documentation might help](https://docs.python.org/3/tutorial/datastructures.html).
```py
# Your answer here
```
#### Bonus
Print out each key-value pair in the following format - "KEY's is equal to VALUE" -- using a function. [The Python documentation might help](https://docs.python.org/3/tutorial/datastructures.html).
```py
# Your answer here
```
@@ -0,0 +1,142 @@
### Assorted Data Types
#### What are the outputs and/or side effects of the following code snippets?
* Make a guess before testing your answer.
* "Error out" is a valid answer choice.
* Also include a sentence on why you chose your answer.
```py
2 ** 3
```
```text
Your answer.
```
```py
((16 / 4) * (2 + 1)) ** 2
```
```text
Your answer.
```
```py
("a milli " + "a milli") * 3
```
```text
Your answer.
```
```py
("a milli " * 4) / 2
```
```text
Your answer.
```
```py
my_favorite_number = 13
puts "My favorite number is: " + my_favorite_number
```
```text
Your answer.
```
```py
my_favorite_number = 13
puts "My favorite number is: #{my_favorite_number}"
```
```text
Your answer.
```
### Truthiness and Falsiness
#### Which of these evaluate as `false` in Python? Mark all that apply.
```text
[ ] False
[ ] 0
[ ] ""
[ ] None
[ ] [ ] (empty array)
```
#### What are the outputs and/or side effects of the following code snippets?
* Make a guess before testing your answer.
* "Error out" is a valid answer choice.
* Also include a sentence on why you chose your answer.
```py
no_name = ""
if no_name:
print("My name is: " + no_name)
```
```text
Your answer.
```
```py
no_name = None
if no_name:
print("My name is: " + no_name)
```
```text
Your answer.
```
```py
age = 21
if age:
print("My age is: " + no_name)
```
```text
Your answer.
```
```py
age = input()
if age:
print("My age is: " + age)
```
```text
Your answer.
```
### Conditionals
Write the code for the following exercise inside of the `app.py` located in this repo. Run/test your code using `python app.py` in the Terminal.
#### Write FizzBuzz in Python!
Fizz-Buzz is a classic coding exercise that you can create using your knowledge of conditionals and loops. Implement code that does the following...
* Counts from 1 to 100 and prints out something for each number.
* If the number is divisible by 3, print `"Fizz"`.
* If the number is divisible by 5, print `"Buzz"`.
* If the number is divisible by both 3 and 5, print `"FizzBuzz"`.
* If the number does not meet any of the above conditions, just print the number.
Your output should look something like this...
```
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz, 31, 32, Fizz, 34, Buzz, Fizz, ...
```
<details>
<summary><strong>We haven't covered loops yet, so to get you started...</strong></summary>
```py
i = 1
while i <= 100:
# Your code goes in here.
```
</details>
@@ -0,0 +1,4 @@
Clone this repo and answer the questions found in the other `.md` files. You can test your code in the terminal using Pry or running `app.rb`.
**Exercise I:** [Data Types](https://git.generalassemb.ly/ga-dc-wdi-python/python-basics-exercises/blob/master/data-types.md)
**Exercise II:** [Data Collections](https://github.com/ga-dc-wdi-python/python-basics-exercises/blob/master/data-collections.md)

0 comments on commit f4530a5

Please sign in to comment.