Today:
warm_up_list = [4,2,9,4,5,1]
# your code here
answer = warm_up_list[0] ** warm_up_list[4]
print(answer)
1024
# extract elements 2 through 4 of warm_up_list
print(warm_up_list[1:3])
[254, 324]
my_big_string = 'heresabigstringwithnospaces'
print(my_big_string[5:15])
abigstring
states = [ 'AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA','HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME','MI', 'MN', 'MO', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM','NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX','UT', 'VA', 'VT', 'WA', 'WI', 'WV', 'WY']
# your code here
print(states[1:9])
['AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE']
len()
gives you the length of a list or string¶my_list = [1,33,2,23,2,32,42]
print(len(my_list))
7
my_list = ['s','c','i','e','n','c','e']
my_string = 'helpiforgottoputwhitespaceinthissentence'
# your code here
print(len(my_list))
print(len(my_string))
7 40
your_name = input("what is your name? ")
output_statement = 'python remembered your name is: ' + your_name
print(output_statement)
what is your name? vikas python remembered your name is: vikas
input_number = float(input("whats your number? "))
answer = input_number ** 2
print(answer)
whats your number? 23 529.0
if 2 > 1:
print('Math works')
# there is an invisible tab character on the second line
Math works
if 2 > 1
print('Math works')
Input In [6] if 2 > 1 ^ SyntaxError: invalid syntax
if 2 > 1:
print('Math works')
Input In [7] print('Math works') ^ IndentationError: expected an indented block
if 2 > 1:
print('Math works')
print('But python doesnt sometimes')
File <tokenize>:3 print('But python doesnt sometimes') ^ IndentationError: unindent does not match any outer indentation level
if "dogs" > "cats":
print("Dogs really are the best")
Dogs really are the best
a = 100 ** 2
b = 7 ** 4
# your code here
if a > b:
print('a is greater than b')
a is greater than b
Else is like saying 'otherwise' after if: "if this is true, do this. Otherwise, do that"
if 'unix' < 'gui':
print('This sounds wrong')
else:
print('Roman told you so')
Roman told you so
if 1 < 5:
print('5 is greater than 1')
else 1 > 5:
print('1 is greater than 5?? ')
Input In [25] else 1 > 5: ^ SyntaxError: invalid syntax
if 1 < 5:
print('5 is greater than 1')
else:
print('1 is greater than 5?? ')
File <tokenize>:3 else: ^ IndentationError: unindent does not match any outer indentation level
a = 500 * 20
b = 7 ** 9
# your code here
if a > b:
print('a is greater than b')
else:
print('b is greater than a')
b is greater than a
Elif is the partner of if and else:
# If, else and elif
x = float(input("What's your favorite number? : "))
if x == 7:
print("We have the same favorite number!")
elif x < 2:
print("Your favorite number is way less than mine")
elif x < 7:
print("Your favorite number is less than mine")
else:
print("Your favorite number is greater than mine")
What's your favorite number? : 10 Your favorite number is greater than mine
# your code here
x = float(input("What's your favorite number? : "))
if x < 28:
print('your number is less than 28')
elif x > 30:
print('your number is greater than 30')
elif x == 29:
print('thats a nice number')
What's your favorite number? : 100 your number is greater than 30
teachers = ['Roman','Vikas','Sarah','Daniel']
for person in teachers:
print(person + " is a great teacher!")
Roman is a great teacher! Vikas is a great teacher! Sarah is a great teacher! Daniel is a great teacher!
# your code here
alphabet = ['a','b','c','d','e']
for letter in alphabet:
print(letter)
a b c d e
my_list = [1,2,3,4,5]
i = 1
for number in my_list:
i = i + number
print(i)
2 4 7 11 16
for num in range(1,5):
print(num)
1 2 3 4
# your code here
x = 0
for num in range(1,101):
x = x + num
print(x)
5050
x = [1,2,3]
y = [4,5,6]
for outer in x:
for inner in y:
print(outer + inner)
5 6 7 6 7 8 7 8 9
# your code here:
for outer in x:
for inner in y:
number_sum = outer + inner
if number_sum > 7:
print(number_sum)
8 8 9
rna_sequence = 'AUGUUUUUGAUACUUUUAAUUUCCUUACCAACGGCUUUUGCUGUUAUAGGAGAUUUAAAGUGUACUACAGUUUCCAUUAAUGAUGUUGACACUGGUGUUCCUUCUAUUAGCACUGAUACUGUCGAUGUUACUAAUGGUUUAGGUACUUAUUAUGUUUUAGAUCGUGUGUAUUUAAAUACUACGUUGUUGCUUAAUGGUUAUUACCCUACUUCAGGUUCUACAUAUCGUAAUAUGGCACUGAAGGGAACUUUACUAUUGAGCACACUGUGGUUUAAACCACCUUUUCUUUCUGAUUUUACUAAUGG'
#your code here
rna_length = len(rna_sequence)
last_codon_start = rna_length - 3
for codon_start in range(0,last_codon_start):
codon_end = codon_start + 3
current_codon = rna_sequence[codon_start:codon_end]
if current_codon == 'AUG':
print(codon_start)
0 79 82 124 133 151 193 231 301
rna_sequence = 'AUGUUUUUGAUACUUUUAAUUUCCUUACCAACGGCUUUUGCUGUUAUAGGAGAUUUAAAGUGUACUACAGUUUCCAUUAAUGAUGUUGACACUGGUGUUCCUUCUAUUAGCACUGAUACUGUCGAUGUUACUAAUGGUUUAGGUACUUAUUAUGUUUUAGAUCGUGUGUAUUUAAAUACUACGUUGUUGCUUAAUGGUUAUUACCCUACUUCAGGUUCUACAUAUCGUAAUAUGGCACUGAAGGGAACUUUACUAUUGAGCACACUGUGGUUUAAACCACCUUUUCUUUCUGAUUUUACUAAUGG'
stop_codons = ['UGA','UAA','UAG']
#your code here
rna_length = len(rna_sequence)
last_codon_start = rna_length - 3
for codon_start in range(0,last_codon_start):
codon_end = codon_start + 3
current_codon = rna_sequence[codon_start:codon_end]
if current_codon == stop_codons[0]:
print(codon_start)
elif current_codon == stop_codons[1]:
print(codon_start)
elif current_codon == stop_codons[2]:
print(codon_start)
7 16 46 55 77 80 86 107 113 131 139 157 172 191 227 238 256 272 290 299
# your code here
found_start_codons = []
found_stop_codons = []
rna_length = len(rna_sequence)
last_codon_start = rna_length - 3
for codon_start in range(0,last_codon_start):
codon_end = codon_start + 3
current_codon = rna_sequence[codon_start:codon_end]
if current_codon == stop_codons[0]:
found_stop_codons.append(codon_start)
elif current_codon == stop_codons[1]:
found_stop_codons.append(codon_start)
elif current_codon == stop_codons[2]:
found_stop_codons.append(codon_start)
elif current_codon == 'AUG':
found_start_codons.append(codon_start)
print(found_start_codons)
print(found_stop_codons)
[0, 79, 82, 124, 133, 151, 193, 231, 301] [7, 16, 46, 55, 77, 80, 86, 107, 113, 131, 139, 157, 172, 191, 227, 238, 256, 272, 290, 299]