Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
176 changes: 88 additions & 88 deletions lesson04/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

# literal assignment

first = "Dave"
last = "Gray"
# first = "Dave"
# last = "Gray"

# print(type(first))
# print(type(first) == str)
Expand All @@ -17,120 +17,120 @@
# print(isinstance(pizza, str))

# Concatenation
fullname = first + " " + last
print(fullname)
# fullname = first + " " + last
# print(fullname)

fullname += "!"
print(fullname)
# fullname += "!"
# print(fullname)

# Casting a number to a string
decade = str(1980)
print(type(decade))
print(decade)
# # Casting a number to a string
# decade = str(1980)
# print(type(decade))
# print(decade)

statement = "I like rock music from the " + decade + "s."
print(statement)
# statement = "I like rock music from the " + decade + "s."
# print(statement)

# Multiple lines
multiline = '''
Hey, how are you?
# # Multiple lines
# multiline = '''
# Hey, how are you?

I was just checking in.
All good?
# I was just checking in.
# All good?

'''
print(multiline)
# '''
# print(multiline)

# Escaping special characters
sentence = 'I\'m back at work!\tHey!\n\nWhere\'s this at\\located?'
print(sentence)
# # Escaping special characters
# sentence = 'I\'m back at work!\tHey!\n\nWhere\'s this at\\located?'
# print(sentence)

# String Methods
# # String Methods

print(first)
print(first.lower())
print(first.upper())
print(first)
# print(first)
# print(first.lower())
# print(first.upper())
# print(first)

print(multiline.title())
print(multiline.replace("good", "ok"))
print(multiline)
# print(multiline.title())
# print(multiline.replace("good", "ok"))
# print(multiline)

print(len(multiline))
multiline += " "
multiline = " " + multiline
print(len(multiline))
# print(len(multiline))
# multiline += " "
# multiline = " " + multiline
# print(len(multiline))

print(len(multiline.strip()))
print(len(multiline.lstrip()))
print(len(multiline.rstrip()))
# print(len(multiline.strip()))
# print(len(multiline.lstrip()))
# print(len(multiline.rstrip()))

print("")
# print("")

# Build a menu
title = "menu".upper()
print(title.center(20, "="))
print("Coffee".ljust(16, ".") + "$1".rjust(4))
print("Muffin".ljust(16, ".") + "$2".rjust(4))
print("Cheesecake".ljust(16, ".") + "$4".rjust(4))
# # Build a menu
# title = "menu".upper()
# print(title.center(20, "="))
# print("Coffee".ljust(16, ".") + "$1".rjust(4))
# print("Muffin".ljust(16, ".") + "$2".rjust(4))
# print("Cheesecake".ljust(16, ".") + "$4".rjust(4))

print("")
# print("")

# string index values
print(first[1])
print(first[-1])
print(first[1:-1])
print(first[1:])
# # string index values
# print(first[1])
# print(first[-1])
# print(first[1:-1])
# print(first[1:])

# Some methods return boolean data
print(first.startswith("D"))
print(first.endswith("Z"))
# # Some methods return boolean data
# print(first.startswith("D"))
# print(first.endswith("Z"))


# Boolean data type
myvalue = True
x = bool(False)
print(type(x))
print(isinstance(myvalue, bool))
# # Boolean data type
# myvalue = True
# x = bool(False)
# print(type(x))
# print(isinstance(myvalue, bool))

# Numeric data types
# # Numeric data types

# integer type
price = 100
best_price = int(80)
print(type(price))
print(isinstance(best_price, int))
# # integer type
# price = 100
# best_price = int(80)
# print(type(price))
# print(isinstance(best_price, int))

# float type
gpa = 3.28
y = float(1.14)
print(type(gpa))
# # float type
# gpa = 3.28
# y = float(1.14)
# print(type(gpa))

# complex type
comp_value = 5+3j
print(type(comp_value))
print(comp_value.real)
print(comp_value.imag)
# # complex type
# comp_value = 5+3j
# print(type(comp_value))
# print(comp_value.real)
# print(comp_value.imag)

# Built-in functions for numbers
# # Built-in functions for numbers

print(abs(gpa))
print(abs(gpa * -1))
# print(abs(gpa))
# print(abs(gpa * -1))

print(round(gpa))
# print(round(gpa))

print(round(gpa, 1))
# print(round(gpa, 1))


print(math.pi)
print(math.sqrt(64))
print(math.ceil(gpa))
print(math.floor(gpa))
# print(math.pi)
# print(math.sqrt(64))
# print(math.ceil(gpa))
# print(math.floor(gpa))

# Casting a string to a number
zipcode = "10001"
zip_value = int(zipcode)
print(type(zip_value))
# # Casting a string to a number
# zipcode = "10001"
# zip_value = int(zipcode)
# print(type(zip_value))

# Error if you attempt to cast incorrect data
# zip_value = int("New York")
# # Error if you attempt to cast incorrect data
# # zip_value = int("New York")
7 changes: 3 additions & 4 deletions lesson05/rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class RPS(Enum):


print("")
playerchoice = input(
"Enter...\n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
playerchoice = input("Enter...\n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")

player = int(playerchoice)

Expand All @@ -23,8 +22,8 @@ class RPS(Enum):
computer = int(computerchoice)

print("")
print("You chose " + str(RPS(player)).replace('RPS.', '') + ".")
print("Python chose " + str(RPS(computer)).replace('RPS.', '') + ".")
print("You chose " + str(RPS(player)).replace("RPS.", "") + ".")
print("Python chose " + str(RPS(computer)).replace("RPS.", "") + ".")
print("")

if player == 1 and computer == 3:
Expand Down
93 changes: 55 additions & 38 deletions lesson06/lists.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,79 @@
users = ['Dave', 'John', 'Sara']
users = ["John", "Sara", "Dave"]

data = ['Dave', 42, True]
data = ["Dave", 42, True]

emptylist = []

print("Dave" in emptylist)
# print("Dave" in emptylist)

print(users[0])
print(users[-2])
# print(users[0])
# print(users[-2])

print(users.index('Sara'))
# print(users.index('Sara'))

print(users[0:2])
print(users[1:])
print(users[-3:-1])
# print(users[0:2])
# print(users[1:])
# print(users[-3:-1])

print(len(data))
# print(len(data))

users.append('Elsa')
print(users)
# users.append('Elsa')
# print(users)

users += ['Jason']
print(users)
# users += ['Jason']
# print(users)

users.extend(['Robert', 'Jimmy'])
print(users)

# users.extend(data)
# users.extend(['Robert', 'Jimmy'])
# print(users)

users.insert(0, 'Bob')
print(users)
# # users.extend(data)
# # print(users)

users[2:2] = ['Eddie', 'Alex']
print(users)
# users.insert(0, 'Bob') #Added to beginning of the list
# print(users)

users[1:3] = ['Robert', 'JPJ']
print(users)
# users[2:2] = ['Eddie', 'Alex'] #Added not replaced anyone
# print(users)

users.remove('Bob')
print(users)
# users[1:3] = ['Robert', 'JPJ'] #replaced two values
# print(users)

print(users.pop())
print(users)
# users.remove('Bob') #first user
# print(users)

del users[0]
print(users)
# print(users.pop()) #last user. Returns user removed.
# print(users)

# del users[0] #specify index
# print(users)

# # del data
# print(data) #error

# del data
data.clear()
print(data)
# data.clear() #empties list but list exists
# print(data)
print(users)

users[1:2] = ['dave']
users[1:2] = ["dave"]
print(users)
users.sort()
print(users)

users.sort(key=str.lower)
print(users)

nums = [4, 42, 78, 1, 5]
nums = [4, 40, 42, 78, 1, 5, 100]
nums.sort()
print(nums)

nums.reverse()
print(nums)

# nums.sort(reverse=True)
# print(nums)

print(sorted(nums, reverse=True))
print(sorted(nums, reverse=True)) # doesn't mutate
print(nums)

numscopy = nums.copy()
Expand All @@ -85,7 +93,7 @@

# Tuples

mytuple = tuple(('Dave', 42, True))
mytuple = tuple(("Dave", 42, True))

anothertuple = (1, 4, 2, 8, 2, 2)

Expand All @@ -94,7 +102,8 @@
print(type(anothertuple))

newlist = list(mytuple)
newlist.append('Neil')
anotherTuple = list()
anotherTuple.append("Neil")
newtuple = tuple(newlist)
print(newtuple)

Expand All @@ -103,4 +112,12 @@
print(two)
print(hey)

print(anothertuple.count(2))
print(anothertuple.count(2)) # returns number of occurences


# Lists and Tuples
# Lists use [] and are mutable
# Tuples use () and are immutable
# They both are ordered, have indexing / slicing methods, and duplicate elements
# Sets
# Sets are not ordered, not index based, don't have duplicate elements
Loading