# [ ] print out the "physical states of matter" (matter_states) in 4 sentences using list iteration
# each sentence should be of the format: "Solid - is state of matter #1"
matter_states = ['solid', 'liquid', 'gas', 'plasma']
x = 0
for matter in matter_states:
x += 1
print(matter.capitalize(), "is state of matter #", x)
# [ ] iterate the list (birds) to see any bird names start with "c" and remove that item from the list
# print the birds list before and after removals
birds = ["turkey", "hawk", "chicken", "dove", "crow"]
print(birds)
for bird in birds:
if bird.startswith("c"):
birds.remove(bird)
else:
pass
print(birds)
# the team makes 1pt, 2pt or 3pt baskets
# [ ] print the occurace of each type of basket(1pt, 2pt, 3pt) & total points using the list baskets
baskets = [2,2,2,1,2,1,3,3,1,2,2,2,2,1,3]
print("there are",baskets.count(2),"two point baskets")
print("there are",baskets.count(1),"one point baskets")
print("there are",baskets.count(3),"three point baskets")
sum = 0
for basket in baskets:
sum += basket
print("The total is",sum)
# [ ] using range() print "hello" 4 times
str_value = "hello"
for count in range(0, 4):
print(str_value)
# [ ] find spell_list length
# [ ] use range() to iterate each half of spell_list
# [ ] label & print the first and second halves
spell_list = ["Tuesday", "Wednesday", "February", "November", "Annual", "Calendar", "Solstice"]
length = len(spell_list)
length_half = int(len(spell_list)/2)
for word in range(length_half):
print(spell_list[word])
for word in range(length_half, length):
print(spell_list[word])
# [ ] build a list of numbers from 20 to 29: twenties
# append each number to twenties list using range(start,stop) iteration
# [ ] print twenties
twenties = []
for num in range(20, 30):
twenties.append(num)
print(twenties)
# [ ] iterate through the numbers populated in the list twenties and add each number to a variable: total
# [ ] print total
total = 0
for num in twenties:
total += num
print(total)
# check your answer above using range(start,stop)
# [ ] iterate each number from 20 to 29 using range()
# [ ] add each number to a variable (total) to calculate the sum
# should match earlier task
total = 0
for num in range(20, 30):
total += num
print(total)
# [ ] create a list of odd numbers (odd_nums) from 1 to 25 using range(start,stop,skip)
# [ ] print odd_nums
# hint: odd numbers are 2 digits apart
odd_nums = list(range(1, 26, 2))
print(odd_nums)
# [ ] create a Decending list of odd numbers (odd_nums) from 25 to 1 using range(start,stop,skip)
# [ ] print odd_nums, output should resemble [25, 23, ...]
odd_nums = list(range(25, 0, -2))
print(odd_nums)
# the list, elements, contains the names of the first 20 elements in atomic number order
# [ ] print the even number elements "2 - Helium, 4 - Beryllium,.." in the list with the atomic number
elements = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \
'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', \
'Potassium', 'Calcium']
length = len(elements)
for word in range(, length, 2):
print(word + 1, "-" ,elements[word])
# [ ] # the list, elements_60, contains the names of the first 60 elements in atomic number order
# [ ] print the odd number elements "1 - Hydrogen, 3 - Lithium,.." in the list with the atomic number elements_60
elements_60 = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', \
'Oxygen', 'Fluorine', 'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', \
'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', 'Potassium', 'Calcium', 'Hydrogen', \
'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \
'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', \
'Argon', 'Potassium', 'Calcium', 'Scandium', 'Titanium', 'Vanadium', 'Chromium', 'Manganese', \
'Iron', 'Cobalt', 'Nickel', 'Copper', 'Zinc', 'Gallium', 'Germanium', 'Arsenic', 'Selenium', \
'Bromine', 'Krypton', 'Rubidium', 'Strontium', 'Yttrium', 'Zirconium']
length = len(elements_60)
for word in range(0, length, 2):
print(word + 1, "-" ,elements_60[word])
# [ ] print the combined lists (numbers_1 & numbers_2) using "+" operator
numbers_1 = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
# pythonic casting of a range into a list
numbers_2 = list(range(30,50,2))
print("numbers_1:",numbers_1)
print("numbers_2",numbers_2)
print(numbers_1 + numbers_2)
# [ ] print the combined element lists (first_row & second_row) using ".extend()" method
first_row = ['Hydrogen', 'Helium']
second_row = ['Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon']
print("1st Row:", first_row)
print("2nd Row:", second_row)
first_row.extend(second_row)
print(first_row)
# [ ] create the program: combined 3 element rows
elem_1 = ['Hydrogen', 'Helium']
elem_2 = ['Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon']
elem_3 = ['Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon']
elem_1.extend(elem_2)
elem_1.extend(elem_3)
print(elem_1)
# [ ] .extend() jack_jill with "next_line" string - print the result
jack_jill = ['Jack', 'and', 'Jill', 'went', 'up', 'the', 'hill']
next_line = ['To', 'fetch', 'a', 'pail', 'of', 'water']
jack_jill.extend(next_line)
new_line = " ".join(jack_jill)
print(new_line)
# [ ] use .reverse() to print elements starting with "Calcium", "Chlorine",... in reverse order
elements = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \
'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', \
'Potassium', 'Calcium']
elements.reverse()
for element in elements:
print(element, end = ", ")
# [ ] print words in spell_list that 8 or more characters in length in reverse order
spell_list = ["Tuesday", "Wednesday", "February", "November", "Annual", "Calendar", "Solstice"]
spell_list.reverse()
for word in spell_list:
if len(word)>=8:
print(word)
else:
pass
# [ ] sort the list element, so names are in alphabetical order and print elements
elements = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', \
'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', \
'Potassium', 'Calcium']
elements.sort()
print(elements)
# [ ] print the list, numbers, sorted and then below print the original numbers list
numbers = [2,2,2,1,2,1,3,3,1,2,2,2,2,1,3]
new_numbers = sorted(numbers)
print(new_numbers)
print(numbers)
# [ ] split the string, daily_fact, into a list of word strings: fact_words
# [ ] print each string in fact_words in upper case on it's own line
daily_fact = "Did you know that there are 1.4 billion students in the world?"
fact_words = daily_fact.split()
for word in fact_words:
print(word.upper())
# [ ] convert the string, code_tip, into a list made from splitting on the letter "o"
code_tip = "Read the instructions carefully"
code_tip_list = code_tip.split("o")
print(code_tip_list)
# [ ] split poem on "b" to create a list: poem_words
# [ ] print poem_words by iterating the list
poem = "The bright brain, has bran!"
poem_list = poem.split("b")
for word in poem_list:
print(word)
# [ ] print a comma separated string output from the list of Halogen elements using ".join()"
halogens = ['Chlorine', 'Florine', 'Bromine', 'Iodine']
halogens_phrase = ", ".join(halogens)
print(halogens_phrase)
# [ ] split the sentence, code_tip, into a words list
# [ ] print the joined words in the list with no spaces in-between
# [ ] Bonus: capitalize each word in the list before .join()
code_tip ="Read code aloud or explain the code step by step to a peer"
word_list = code_tip.split()
new_code_tip = "".join(word_list)
print(new_code_tip)
# [ ] cast the long_word into individual letters list
# [ ] print each letter on a line
long_word = 'decelerating'
letters_list = list(long_word)
for letter in letters_list:
print(letter)
# [ ] use use end= in print to output each string in questions with a "?" and on new lines
questions = ["What's the closest planet to the Sun", "How deep do Dolphins swim", "What time is it"]
for question in questions:
print(question, end = "?\n")
# [ ] print each item in foot bones
# - capitalized, both words if two word name
# - separated by a comma and space
# - and keeping on a single print line
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
"intermediate cuneiform", "medial cuneiform"]
for bone in foot_bones:
print(bone.title(), end = ", ")