Skip to content

Commit

Permalink
commenting on chapter 2 and 3
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHollamby committed Mar 16, 2021
1 parent 052b964 commit 4351cf9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Chapter 2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#create a variable
p_name = 'Ben'

#print() print string hello, with variable p_name
print("Hello " + p_name + "!")

# .upper() makes all capitals
print(p_name.upper())
#.lower() makes all lowercase
print(p_name.lower())
#.title() capitalises first letter of each word
print(p_name.title())

print('a famous person once said "that aint me"')
Expand All @@ -15,14 +20,16 @@
print(famous_person.title() + message)

print("Python")
#\t adds a tab space
print("\tPython")

#\n makes a new line
print(f'\t{famous_person},' + f'\n {message}')

white_space = " Ben . "

print(white_space)

#lstrip() strips any whitespace on the left, rstrip() strips from the right, strip() removes all white space
print(white_space.lstrip())
print(white_space.rstrip())
print(white_space.strip())
Expand Down
42 changes: 40 additions & 2 deletions Chapter 3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# [] is a list
names = ["ben", "angela", "alice"]
print(names)
#using [number] grabs item in the list. Starts from 0
print(names[0])
print(names[1])
print(names[2])
Expand All @@ -20,8 +22,14 @@
print("Hello " + dinner_list[1].title() + ", would you like to come to dinner?")
print("Hello " + dinner_list[2].title() + ", would you like to come to dinner?")

print("Unfortunately, " + names[1].title() + " can't make it for dinner")
#len(names) will show how many items in a list
#str(len(names)) will turn that into a string if you want to print it
coming = str(len(dinner_list))
print("\nThere are " + coming + " people coming to dinner")

print("\nUnfortunately, " + names[1].title() + " can't make it for dinner")

#modifies the object in the list at position 1 from Alice to Fermi
dinner_list[1] = "fermi"

print("Hello " + dinner_list[0].title() + ", would you like to come to dinner?")
Expand All @@ -30,8 +38,10 @@

print("\nHey, " + dinner_list[0].title() + ", " + dinner_list[1].title() + ", " + dinner_list[2].title() + ", we now have a bigger table, does anyone want to invite anyone?")

# .inset(0, kelly) inserts name into postion zero
dinner_list.insert(0, "kelly")
dinner_list.insert(2, "chase")
#.append adds item to the end of the list
dinner_list.append("aaron")

print("\nHello " + dinner_list[0].title() + ", would you like to come to dinner?")
Expand All @@ -41,8 +51,12 @@
print("Hello " + dinner_list[4].title() + ", would you like to come to dinner?")
print("Hello " + dinner_list[5].title() + ", would you like to come to dinner?")

coming = str(len(dinner_list))
print("\nThere are " + coming + " people coming to dinner")

print("\nUnfortunately the table is not going to make it in time, and there is only space for two people :(")

# dinner_list.pop() removes the last item from the list. In the below case we are taking that last item and putting it into a variable so we can inform user of cancelation
dinner_list_popped = dinner_list.pop()
print("Sorry, " + dinner_list_popped + " we have to cancel your seat, I am so sorry!")
dinner_list_popped = dinner_list.pop()
Expand All @@ -52,9 +66,33 @@
dinner_list_popped = dinner_list.pop()
print("Sorry, " + dinner_list_popped + " we have to cancel your seat, I am so sorry!")

coming = str(len(dinner_list))
print("\nThere are " + coming + " people coming to dinner")

print(dinner_list)

# del in combination with [-1] deletes the last item in the list
del dinner_list[-1]
print(dinner_list)
del dinner_list[-1]
print(dinner_list)
print(dinner_list)

locations = ["antarctica", "siberia", "russia", "egypt", "jordan"]
print(locations)
#alphabetically sorts locations, not permanent
print(sorted(locations))
print(locations)
#reverse=True sorts locations variables not permanent
print(sorted(locations, reverse=True))
print(locations)
# reverse reverses the list permanently
locations.reverse()
print(locations)
locations.reverse()
print(locations)
# .sort sorts the list alphabetically permanent
locations.sort()
print(locations)
#.sort(reverse=True) sorts list in reverse alphabetical permanently
locations.sort(reverse=True)
print(locations)
Empty file added Chapter 4.py
Empty file.

0 comments on commit 4351cf9

Please sign in to comment.