# [ ] 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)
Solid is state of matter # 1
Liquid is state of matter # 2
Gas is state of matter # 3
Plasma is state of matter # 4
# [ ] 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)
['turkey', 'hawk', 'chicken', 'dove', 'crow']
['turkey', 'hawk', 'dove']
# 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)
there are 8 two point baskets
there are 4 one point baskets
there are 3 three point baskets
The total is 29
# [ ] using range() print "hello" 4 times
str_value = "hello"
for count in range(0, 4):
print(str_value)
hello
hello
hello
hello
# [ ] 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])
Tuesday
Wednesday
February
November
Annual
Calendar
Solstice
# [ ] 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)
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
# [ ] 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)
245
# 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)
245
# [ ] 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)
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]
# [ ] 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)
[25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]
# 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])
2 - Helium
4 - Beryllium
6 - Carbon
8 - Oxygen
10 - Neon
12 - Magnesium
14 - Silicon
16 - Sulfur
18 - Argon
20 - Calcium
# [ ] # 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])
1 - Hydrogen
3 - Lithium
5 - Boron
7 - Nitrogen
9 - Fluorine
11 - Sodium
13 - Aluminum
15 - Phosphorus
17 - Chlorine
19 - Potassium
21 - Hydrogen
23 - Lithium
25 - Boron
27 - Nitrogen
29 - Fluorine
31 - Sodium
33 - Aluminum
35 - Phosphorus
37 - Chlorine
39 - Potassium
41 - Scandium
43 - Vanadium
45 - Manganese
47 - Cobalt
49 - Copper
51 - Gallium
53 - Arsenic
55 - Bromine
57 - Rubidium
59 - Yttrium
# [ ] 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)
numbers_1: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
numbers_2 [30, 32, 34, 36, 38, 40, 42, 44, 46, 48]
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]
# [ ] 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)
1st Row: ['Hydrogen', 'Helium']
2nd Row: ['Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon']
['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon']
# [ ] 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)
['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon', 'Sodium', 'Magnesium', 'Aluminum', 'Silicon', 'Phosphorus', 'Sulfur', 'Chlorine', 'Argon']
# [ ] .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)
Jack and Jill went up the hill To fetch a pail of water
# [ ] 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 = ", ")
Calcium, Potassium, Argon, Chlorine, Sulfur, Phosphorus, Silicon, Aluminum, Magnesium, Sodium, Neon, Fluorine, Oxygen, Nitrogen, Carbon, Boron, Beryllium, Lithium, Helium, Hydrogen,
# [ ] 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
Solstice
Calendar
November
February
Wednesday
# [ ] 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)
['Aluminum', 'Argon', 'Beryllium', 'Boron', 'Calcium', 'Carbon', 'Chlorine', 'Fluorine', 'Helium', 'Hydrogen', 'Lithium', 'Magnesium', 'Neon', 'Nitrogen', 'Oxygen', 'Phosphorus', 'Potassium', 'Silicon', 'Sodium', 'Sulfur']
# [ ] 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)
[1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3]
[2, 2, 2, 1, 2, 1, 3, 3, 1, 2, 2, 2, 2, 1, 3]
# [ ] 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())
DID
YOU
KNOW
THAT
THERE
ARE
1.4
BILLION
STUDENTS
IN
THE
WORLD?
# [ ] 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)
['Read the instructi', 'ns carefully']
# [ ] 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)
The
right
rain, has
ran!
# [ ] 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)
Chlorine, Florine, Bromine, Iodine
# [ ] 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)
Readcodealoudorexplainthecodestepbysteptoapeer
# [ ] 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)
d
e
c
e
l
e
r
a
t
i
n
g
# [ ] 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")
What's the closest planet to the Sun?
How deep do Dolphins swim?
What time is it?
# [ ] 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 = ", ")
Calcaneus, Talus, Cuboid, Navicular, Lateral Cuneiform, Intermediate Cuneiform, Medial Cuneiform,