8000 Initial commit · pakydu/c9-python-getting-started@b09501b · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b09501b

Browse files
author
Christopher Harrison
committed
Initial commit
1 parent 3f33727 commit b09501b

File tree

133 files changed

+1716
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1716
-38
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
env
2+
3+
# Created by https://www.gitignore.io/api/python,visualstudiocode
4+
# Edit at https://www.gitignore.io/?templates=python,visualstudiocode
5+
6+
### Python ###
17
# Byte-compiled / optimized / DLL files
28
__pycache__/
39
*.py[cod]
@@ -20,6 +26,8 @@ parts/
2026
sdist/
2127
var/
2228
wheels/
29+
pip-wheel-metadata/
30+
share/python-wheels/
2331
*.egg-info/
2432
.installed.cfg
2533
*.egg
@@ -38,6 +46,7 @@ pip-delete-this-directory.txt
3846
# Unit test / coverage reports
3947
htmlcov/
4048
.tox/
49+
.nox/
4150
.coverage
4251
.coverage.*
4352
.cache
@@ -72,9 +81,20 @@ target/
7281
# Jupyter Notebook
7382
.ipynb_checkpoints
7483

84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
7588
# pyenv
7689
.python-version
7790

91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
7898
# celery beat schedule file
7999
celerybeat-schedule
80100

@@ -102,3 +122,21 @@ venv.bak/
102122

103123
# mypy
104124
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
### VisualStudioCode ###
132+
.vscode/*
133+
!.vscode/settings.json
134+
!.vscode/tasks.json
135+
!.vscode/launch.json
136+
!.vscode/extensions.json
137+
138+
### VisualStudioCode Patch ###
139+
# Ignore all local history of files
140+
.history
141+
142+
# End of https://www.gitignore.io/api/python,visualstudiocode
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# I check to see if the requirements for honour roll are met
2+
gpa = float(input('What was your Grade Point Average? '))
3+
lowest_grade = float(input('What was your lowest grade? '))
4+
5+
# Boolean variables allow you to remember a True/False value
6+
if gpa >= .85 and lowest_grade >= .70:
7+
honour_roll = True
8+
else:
9+
honour_roll = False
10+
11+
# Somewhere later in your code if you need to check if students is
12+
# on honour roll, all I need to do is check the boolean variable
13+
# I set earlier in my code
14+
if honour_roll:
15+
print('You made honour roll')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# When you join a hockey team you get your name on the back of the jersey
2+
# but the jersey may not be big enough to hold all the letters
3+
# Ask the user for their first name
4+
5+
# Ask the user for their last name
6+
7+
# if first name is < 10 characters and last name is < 10 characters
8+
# print first and last name on the jersey
9+
# if first name >= 10 characters long and last name is < 10 characters
10+
# print first initial of first name and the entire last name
11+
# if first name < 10 characters long and last name is >= 10 characters
12+
# print entire first name and first initial of last name
13+
# if first name >= 10 characters long and last name is >= 10 characters
14+
# print last name only
15+
16+
# Test with the following values
17+
# first name: Susan last name: Ibach
18+
# output: Susan Ibach
19+
# first name: Susan last name: ReallyLongLastName
20+
# output: Susan R.
21+
# first name: ReallyLongFirstName last name: Ibach
22+
# output: R. Ibach
23+
# first name: ReallyLongFirstName last name: ReallyLongLastName
24+
# output: ReallyLongLastName
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# When you join a hockey team you get your name on the back of the jersey
2+
# but the jersey may not be big enough to hold all the letters
3+
# Ask the user for their first name
4+
first_name = input('Please enter your first name: ')
5+
# Ask the user for their last name
6+
last_name = input('Please enter your last name: ')
7+
8+
# if first name is < 10 characters and last name is < 10 characters
9+
# print first and last name on the jersey
10+
# if first name >= 10 characters long and last name is < 10 characters
11+
# print first initial of first name and the entire last name
12+
# if first name < 10 characters long and last name is >= 10 characters
13+
# print entire first name and first initial of last name
14+
# if first name >= 10 characters long and last name is >= 10 characters
15+
# print last name only
16+
17+
# Check length of first name
18+
if len(first_name) >=10:
19+
long_first_name = True
20+
else:
21+
long_first_name = False
22+
23+
# Check length of last name
24+
if len(last_name) >= 10:
25+
long_last_name = True
26+
else:
27+
long_last_name = False
28+
29+
# Evaluate possible jersey print combinations for different lengths
30+
if long_first_name and long_last_name:
31+
print(last_name)
32+
elif long_first_name:
33+
print(first_name[0:1] + '. ' + last_name)
34+
elif long_last_name:
35+
print(first_name + ' ' + last_name[0:1] + '.')
36+
else:
37+
print(first_name + ' ' + last_name)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Complex condition checks
2+
3+
Conditional execution can be completed using the [if](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement) statement.
4+
5+
`if` syntax
6+
7+
```python
8+
if expression:
9+
# code to execute
10+
elif expression:
11+
# code to execute
12+
else:
13+
# code to execute
14+
```
15+
16+
[Boolean values](https://docs.python.org/3/library/stdtypes.html#boolean-values) can be either `False` or `True`
17+
18+
[Boolean operators](https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not)
19+
20+
- **x *or* y** - If either x **OR** y is true, the expression is executed
21+
- **x *and* y** - If x **AND** y are both true, the expression is executed
22+
23+
[Comparison operators](https://docs.python.org/3/library/stdtypes.html#comparisons)
24+
25+
- < less than
26+
- < greater than
27+
- == is equal to
28+
- \>= greater than or equal to
29+
- <= less than or equal to
30+
- != not equal to
31+
- **x *in* [a,b,c]** Does x match the value of a, b, or c
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# A student makes honour roll if their average is >=85
2+
# and their lowest grade is not below 70
3+
gpa = float(input('What was your Grade Point Average? '))
4+
lowest_grade = input('What was your lowest grade? ')
5+
lowest_grade = float(lowest_grade)
6+
7+
if gpa >= .85 and lowest_grade >= .70:
8+
print('You made the honour roll')
9+

11 - Collections/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Collections
2+
3+
Collections are groups of items. Python supports several types of collections. Three of the most common are dictionaries, lists and arrays.
4+
5+
## Lists
6+
7+
[Lists](https://docs.python.org/3/tutorial/introduction.html#lists) are a collection of items. Lists can be expanded or contracted as needed, and can contain any data type. Lists are most commonly used to store a single column collection of information, however it is possible to [nest lists](https://docs.python.org/3/tutorial/datastructures.html#nested-list-comprehensions)
8+
## Arrays
9+
10+
[Arrays](https://docs.python.org/3/library/array.html) are similar to lists, however are designed to store a uniform basic data type, such as integers or floating point numbers.
11+
12+
## Dictionaries
13+
14+
[Dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) are key/value pairs of a collection of items. Unlike a list where items can only be accessed by their index or value, dictionaries use keys to identify each item.

11 - Collections/arrays.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from array import array
2+
scores = array('d')
3+
scores.append(97)
4+
scores.append(98)
5+
print(scores)

11 - Collections/common-operations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
names = ['Christopher', 'Susan']
2+
print(len(names)) # Get the number of items
3+
names.insert(0, 'Bill') # Insert before index
4+
print(names)

11 - Collections/dictionaries.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
person = {'first': 'Christopher'}
2+
person['last'] = 'Harrison'
3+
print(person)
4+
print(person['first'])

11 - Collections/lists.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
names = ['Christopher', 'Susan']
2+
scores = []
3+
scores.append(98)
4+
scores.append(99)
5+
print(names)
6+
print(scores)

11 - Collections/ranges.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
names = ['Susan', 'Christopher', 'Bill']
2+
presenters = names[0:2] # Get the first two items
3+
# Starting index and number of items to retrieve
4+
5+
print(names)
6+
print(presenters)

12 - Loops/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Loops
2+
3+
## For loops
4+
5+
[For loops](https://docs.python.org/3/reference/compound_stmts.html#the-for-statement) takes each item in an array or collection in order, and assigns it to the variable you define.
6+
7+
``` python
8+
names = ['Christopher', 'Susan']
9+
for name in names:
10+
print(name)
11+
```
12+
13+
## While loops
14+
15+
[While loops](https://docs.python.org/3/reference/compound_stmts.html#the-while-statement) perform an operation as long as a condition is true.
16+
17+
``` python
18+
names = ['Christopher', 'Susan']
19+
index = 0
20+
while index < len(names):
21+
name = names[index]
22+
print(name)
23+
index = index + 1
24+
```

12 - Loops/for.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
for name in ['Christopher', 'Susan']:
2+
print(name)

12 - Loops/number.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# range creates an array
2+
# First parameter is the starter
3+
# Second indicates the number of numbers to create
4+
# range(0, 2) creates [0, 1]
5+
for index in range(0, 2):
6+
print(index)

12 - Loops/while.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
names = ['Christopher', 'Susan']
2+
index = 0
3+
while index < len(names):
4+
print(names[index])
5+
# Change the condition!!
6+
index = index + 1

13 - Functions/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Functions
2+
3+
Functions allow you to take code that is repeated and move it to a module that can be called when needed. Functions are defined with the `def` keyword and must be declared before the function is called in your code. Functions can accept parameters and return values.
4+
5+
- [Functions](https://docs.python.org/3/tutorial/controlflow.html#defining-functions)
6+
7+
```python
8+
def functionname(parameter):
9+
# code to execute
10+
return value
11+
```

13 - Functions/code_challenge.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Create a calculator function
2+
# The function should accept three parameters:
3+
# first_number: a numeric value for the math operation
4+
# second_number: a numeric value for the math operation
5+
# operation: the word 'add' or 'subtract'
6+
# the function should return the result of the two numbers added or subtracted
7+
# based on the value passed in for the operator
8+
#
9+
# Test your function with the values 6,4, add
10+
# Should return 10
11+
#
12+
# Test your function with the values 6,4, subtract
13+
# Should return 2
14+
#
15+
# BONUS: Test your function with the values 6, 4 and divide
16+
# Have your function return an error message when invalid values are received
17+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create a calculator function
2+
# The function should accept three parameters:
3+
# first_number: a numeric value for the math operation
4+
# second_number: a numeric value for the math operation
5+
# operation: the word 'add' or 'subtract'
6+
# the function should return the result of the two numbers added or subtracted
7+
# based on the value passed in for the operator
8+
#
9+
10+
def calculator(first_number, second_number, operation):
11+
if operation.upper() == 'ADD':
12+
return(float(first_number) + float(second_number))
13+
elif operation.upper() =='SUBTRACT':
14+
return(float(first_number) - float(second_number))
15+
else:
16+
return('Invalid operation please specify ADD or SUBTRACT')
17+
# Test your function with the values 6,4, add
18+
# Should return 10
19+
#
20+
print('Adding 6 + 4 = ' + str(calculator(6,4,'add')))
21+
# Test your function with the values 6,4, subtract
22+
# Should return 2
23+
print('Subtracting 6 - 4 = ' + str(calculator(6,4,'subtract')))
24+
# Test your function with the values 6,4, divide
25+
# Should return some sort of error message
26+
print('Dividing 6 / 4 = ' + str(calculator(6,4,'divide')))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Create function get_initial to accept a name and
2+
# return the first letter of the name in uppercase
3+
# Parameters:
4+
# name: the name of a person
5+
# Return value:
6+
# first letter of name passed in as a parameter in uppercase
7+
def get_initial(name):
8+
initial = name[0:1].upper()
9+
return initial
10+
11+
# This program will ask for someone's name and return the initials
12+
first_name = input('Enter your first name: ')
13+
# Call get_initial to retrieve initial of name
14+
first_name_initial = get_initial(first_name)
15+
16+
middle_name = input('Enter your middle name: ')
17+
# Call get_initial to retrieve initial of name
18+
middle_name_initial = get_initial(middle_name)
19+
20+
last_name = input('Enter your last name: ')
21+
# Call get_initial to retrieve initial of name
22+
last_name_initial = get_initial(last_name)
23+
24+
print('Your initials are: ' + first_name_initial \
25+
+ middle_name_initial + last_name_initial)

13 - Functions/get_initials.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Ask for a name and return the initials
2+
first_name = input('Enter your first name: ')
3+
first_name_initial = first_name[0:1]
4+
5+
middle_name = input('Enter your middle name: ')
6+
middle_name_initial = middle_name[0:1]
7+
8+
last_name = input('Enter your last name: ')
9+
last_name_initial = last_name[0:1]
10+
11+
print('Your initials are: ' + first_name_initial \
12+
+ middle_name_initial + last_name_initial)
13+

0 commit comments

Comments
 (0)
0