# Exercise 1.
# Extract the third character in the string and change it to uppercase. Print the result.
string = 'Hello, World!'
# Exercise 2.
# Extract the 5th, 7th, and 9th characters in the number string. Sum them and print the result.
num_string = '783264811953678991250'
# Exercise 3.
# Replace every '0' with '1'. Print the result.
binary_str = '10100001000100101110010100100111101001000100010101011100010'
# Exercise 4.
# Multiply the 5th and last elements of the given list. Print the result.
lst = [12, 7, 42.2, 66, -4, -21, 7, 65, 12, 8, -1, 9]
# Exercise 5.
# Print the first 3 elements of the given list.
subjects = ['Biology', 'History', 'Chemistry', 'Calculus', 'English']
# Exercise 6.
# Create a new list where each number in the given list is converted to a string type.
nums = [22, 34, 3.14, 42, 0, 11.2]
# Exercise 7.
# Remove strings that are longer than 6 characters. Print the modified list.
string_list = ['borrelia', 'tick', 'evolution', 'tree', 'bioinformatics', 'bio', 'analysis', 'lyme', 'data']
# Exercise 8.
# Count the number of G's and C's in the given string.
dna = "GAGCACATATGAGAGTGTTAGAACTGGACGTGCGGTTTCTCTGCGAAGAACACCTCGAGCTGTTGCGTTGTTGCGCTGCCTAGATGCAGT"
# Exercise 9.
# Use list comprehension to create a new list where every word from the old list is in uppercase and has an
# exclamation point after it. Example: 'word' --> 'WORD!'
words = ['hello', 'world', 'python', 'genetics', 'rna', 'protein']
# Exercise 10.
# Use list comprehension to create a new list of numbers where each odd number in the given list is multiplied by 5.
numbers = [3, 4, 78, 56, 32, 11, 91, 0, 39, 99, 101, 222, 43]
# Exercise 11.
# Convert the given sequence of codons into one string.
codons = 'atg, caa, aag, gat, cca, tgt, ttc, cgg'
# Exercise 12.
# Write a function that takes in a list of numbers and returns the mean value.
nums = [632, 540, 311, 784, 421, 500, 889, 720, 613]
# Exercise 13.
# Write a function that performs trancription on a given DNA string and returns an RNA string.
# Base pairs: a-u, c-g, , g-c, t-a
dna1 = 'acacggcttaa'
dna2 = 'tcaaccgttcagtga'
# Exercise 14.
# Create a new list containing sums of each inner list.
nested_list = [[34, 56, -22, -4, 29],
[56, 92, 102, 121, 7],
[92, 37, 80, -12, 35],
[-9, 0, -15, -23, 56],
[23, 54, 37, 120, 57]]
# Exercise 15.
# Write a function that takes in a sentence string and returns a dictionary where every key is a word of the
# sentence and every value is the length of that word.
string = 'The quick brown fox jumps over the lazy dog'
# Exercise 16.
# Print the last row of the given 2D array.
import numpy as np
array = np.array([[34, 56, -22, -4, 29],
[56, 92, 102, 121, 7],
[92, 37, 80, -12, 35],
[-9, 0, -15, -23, 56],
[23, 54, 37, 120, 57]])
# Exercise 17.
# Print the first three rows of the given array.
array = np.array([[34, 56, -22, -4, 29],
[56, 92, 102, 121, 7],
[92, 37, 80, -12, 35],
[-9, 0, -15, -23, 56],
[23, 54, 37, 120, 57]])
# Exercise 18.
# Print the first element of the second row.
array = np.array([[34, 56, -22, -4, 29],
[56, 92, 102, 121, 7],
[92, 37, 80, -12, 35],
[-9, 0, -15, -23, 56],
[23, 54, 37, 120, 57]])
# Exercise 19.
# Print columns 2 and 4 of the given array.
array = np.array([[34, 56, -22, -4, 29],
[56, 92, 102, 121, 7],
[92, 37, 80, -12, 35],
[-9, 0, -15, -23, 56],
[23, 54, 37, 120, 57]])
# Exercise 20.
# Select all negative values of the given array.
array = np.array([[34, 56, -22, -4, 29],
[56, 92, 102, 121, 7],
[92, 37, 80, -12, 35],
[-9, 0, -15, -23, 56],
[23, 54, 37, 120, 57]])
# Use the dataframe below to complete the exercises.
import pandas as pd
data = [[5.1, 3.5, 1.4, 0.2, 'Setosa'],
[4.9, 3.0, 1.4, 0.2, 'Setosa'],
[6.5, 3.0, 5.2, 2.0, 'Virginica'],
[7.0, 3.2, 4.7, 1.4, 'Versicolor'],
[5.9, 3.2, 4.8, 1.8, 'Versicolor'],
[6.3, 3.3, 6.0, 2.5, 'Virginica']]
cols = ['sepal.length', 'sepal.width', 'petal.length', 'petal.width', 'variety']
df = pd.DataFrame(data, columns = cols)
df
# Exercise 21.
# Print the sepal.length and petal.width columns using labels.
# Exercise 22.
# Print the first 3 columns using labels.
# Exercise 23.
# Print rows 3-5 using integer indexing.
# Exercise 24.
# Select the third column using integer indexing.
# Exercise 25.
# Print the mean of the petal.length column.
# Exercise 26.
# Print the sums of all length columns
# Exercise 27.
# Plot a line chart. Label the axes and add a title.
%matplotlib inline
import matplotlib.pyplot as plt
x = [0.2, 0.6, 0.8, 1.2, 1.6]
y = [0.4, 1.2, 1.6, 2.4, 3.2]