Skip to content

Commit b6c830a

Browse files
committed
Initial Commit
1 parent 96a2a10 commit b6c830a

45 files changed

Lines changed: 1037 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for Python programming best practices
3+
4+
5+
# 1. Understand the importance of whitespace
6+
7+
8+
# 2. Use descriptive variable and function names
9+
10+
11+
# 3. Write good comments
12+
13+
14+
# 4. Format code to be readable
15+
16+

‎Finished/Ch2/complex_finished.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for complex types
3+
4+
# Sequences: Lists and Tuples
5+
# These are -- surprise -- sequences of values
6+
mylist = [0, 1, "two", 3.2, False]
7+
print(len(mylist))
8+
9+
# to access a member of a sequence type, use []
10+
print(mylist[2])
11+
print(mylist[-1])
12+
mylist[0] = 1
13+
print(mylist[0])
14+
15+
# add a list to another list
16+
anotherlist = [5, 6.0, "seven"]
17+
mylist = mylist + anotherlist
18+
print(anotherlist)
19+
20+
# use slices to get parts of a sequence
21+
print(mylist[1:4])
22+
print(mylist[1:4:2])
23+
24+
# you can use slices to reverse a sequence
25+
print(mylist[::-1])
26+
27+
# Tuples are like lists, but they are immutable
28+
mytuple = (0, 1, 2, "three")
29+
print(mytuple[1])
30+
31+
# Sets are also sequences, but they contain unique values
32+
myset = {1, 2, 3, 2, 4, "hey"}
33+
print(myset)
34+
35+
# Test for membership
36+
print(1 in mylist)
37+
print(3 in mytuple)
38+
print(5 in myset)
39+
40+
# Dictionary: a key-value data structure
41+
mydict = {
42+
"one" : 1,
43+
"two" : 2
44+
}
45+
46+
# dictionaries are accessed via keys
47+
print(mydict["one"])
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for working with conditional statements
3+
4+
5+
x, y = 10, 100
6+
7+
# conditional flow uses if, elif, else
8+
if x < y:
9+
print("x is less than y")
10+
elif x == y:
11+
print("x is same as y")
12+
else:
13+
print("x is greater than y")
14+
15+
# conditional statements let you use "a if C else b"
16+
result = "x is less than y" if (x < y) else "x is greater than or equal to y"
17+
print(result)

‎Finished/Ch2/functions_finished.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for working with functions
3+
4+
5+
# define a basic function
6+
def hello_func():
7+
print("hello world!")
8+
name = input("What is your name? ")
9+
print("Nice to meet you,", name)
10+
11+
hello_func()
12+
13+
# function that takes parameters and returns a value
14+
def cube(x):
15+
return x*x*x
16+
17+
result = cube(3)
18+
print(result)
19+
20+
# function with default value for an argument
21+
def hello_func(greeting, name=None):
22+
print("hello world!")
23+
if name == None:
24+
name = input("What is your name? ")
25+
print(greeting, name)
26+
27+
hello_func("Nice to meet you", "Mike")
28+
hello_func(name="Joe", greeting="Hi there,")
29+
30+
# function with variable number of arguments
31+
def multi_add(start, *args):
32+
result = start
33+
for x in args:
34+
result = result + x
35+
return result
36+
37+
print(multi_add(10,4,5,10,4))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for HelloWorld
3+
4+
5+
print("hello world!")
6+
name = input("What is your name? ")
7+
print("Nice to meet you,", name)

‎Finished/Ch2/loops_finished.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for working with loops
3+
4+
5+
x = 0
6+
7+
# define a while loop
8+
while (x < 5):
9+
print(x)
10+
x = x + 1
11+
12+
answer = input("Should I stop?")
13+
while answer != "yes":
14+
print(answer)
15+
answer = input("Should I stop?")
16+
17+
# use a for loop over a collection
18+
days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
19+
for d in days:
20+
print(d)
21+
22+
# use the break and continue statements
23+
for d in days:
24+
# if (d == "Wed"):
25+
# break
26+
# if (d == "Thu"):
27+
# continue
28+
print(d)
29+
30+
# using the enumerate() function to get an index and an item
31+
days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
32+
for i, d in enumerate(days):
33+
print(i, d)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Solution for the number counter challenge
3+
4+
def count_numbers(which, nums):
5+
if which != "even" and which != "odd":
6+
return -1
7+
8+
result = 0
9+
for num in nums:
10+
if which == "even" and num % 2 == 0:
11+
result += 1
12+
if which == "odd" and num % 2 != 0:
13+
result += 1
14+
return result
15+
16+
17+
print(count_numbers("even", [1,4,7,10,19,21,24,13,14]))
18+
print(count_numbers("odd", [1,4,7,10,19,21,24,13,14]))
19+
print(count_numbers("blarg", [1,4,7,10,19,21,24,13,14]))

‎Finished/Ch2/variables_finished.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for variables and basic types
3+
4+
5+
# Basic data types in Python: Numbers, Strings, Booleans
6+
# Variable names must start with a letter or _, and can have numbers. They are case sensitive.
7+
myint = 10
8+
myfloat = 13.2576
9+
mystr = "This is a string"
10+
mybool = True
11+
12+
# We can display the content of a variable using the print() function
13+
print(myint)
14+
print(mystr)
15+
16+
# Operators are used to perform operations on variables
17+
print(myint * myfloat)
18+
print(myint % 3)
19+
20+
another_str = "This is another string"
21+
print(mystr + another_str)
22+
print("nom " * 3)
23+
24+
# Logical and comparison operators
25+
print(myint == 10)
26+
print(myfloat != 20)
27+
print(myint > 5 and myfloat < 25.0)
28+
29+
# re-declaring a variable works
30+
myint = "abc"
31+
print(myint)

‎Finished/Ch3/builtin_finished.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for using built-in functions
3+
#
4+
5+
mystring = "The quick, brown fox jumped over the lazy dog!"
6+
mynumbers = [1,3,5,6,9,12,14,17,20,30]
7+
8+
# the len() function calculates the length of a sequence
9+
print(len(mystring))
10+
print(len(mynumbers))
11+
12+
# the max() and min() functions will find the largest and smallest value in a sequence
13+
print(max(mynumbers))
14+
print(min(mynumbers))
15+
16+
# the str() function will return a string version of an object
17+
prefix = "result: "
18+
result = 5
19+
print(prefix + str(result))
20+
print(str(3.1415))
21+
22+
# range(start, stop, step) will create a range of numbers
23+
# You can use ranges along with loops
24+
for i in range(5,len(mystring),2):
25+
print(mystring[i])
26+
27+
# the print function itself is pretty flexible - you can embed variables directly in it
28+
greeting = "Hello!"
29+
count = 10
30+
print(f"{greeting} you are visitor number {count}")

‎Finished/Ch3/classes_finished.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# LinkedIn Learning Python course by Joe Marini
2+
# Example file for working with classes
3+
#
4+
5+
class Vehicle:
6+
def __init__(self, bodystyle):
7+
self.bodystyle = bodystyle
8+
9+
def drive(self, speed):
10+
self.mode = "driving"
11+
self.speed = speed
12+
13+
14+
class Car(Vehicle):
15+
def __init__(self, enginetype):
16+
super().__init__("Car")
17+
self.wheels = 4
18+
self.doors = 4
19+
self.engine = enginetype
20+
21+
def drive(self, speed):
22+
super().drive(speed)
23+
print("Driving my", self.engine, "Car at ", self.speed)
24+
25+
26+
class Motorcycle(Vehicle):
27+
def __init__(self, enginetype, hassidecar):
28+
super().__init__("Motorcycle")
29+
if (hassidecar):
30+
self.wheels = 2
31+
else:
32+
self.wheels = 3
33+
self.doors = 0
34+
self.engine = enginetype
35+
36+
def drive(self, speed):
37+
super().drive(speed)
38+
print("Driving my", self.engine, "motorcylce at ", self.speed)
39+
40+
41+
car1 = Car("gas")
42+
car2 = Car("electric")
43+
mc1 = Motorcycle("gas", True)
44+
45+
print(mc1.wheels)
46+
print(car1.engine)
47+
print(car2.doors)
48+
49+
car1.drive(30)
50+
car2.drive(40)
51+
mc1.drive(50)

0 commit comments

Comments
 (0)