## HW2 ## Write your name. print('-------------------------------------------------------------') print('1. Manipulating Numbers') print('-------------------------------------------------------------') print() 10+3*5 ## Line A x = (1+4)*3 ## Line B 20+x ## Line C y = x ## Line D z = 2*x ## Line E x = x+1.0 ## Line F x**y ## Line G x = x + y + z ## Line H z = (x-1)/y ## Line I ## 1.1: Replace '' with the string ## 'Assignment' or 'Expression'. ## 1.2. Replace '' with the values of ## x, y, and z. Be careful about which variables are ## ints and which are floats. print('After the in line A, x/y/z do not exist.') print('After the in line B, x = 15 and y/z do not exist.') print('After the in line C, .') print('After the in line D, .') print('After the in line E, .') print('After the in line F, .') print('After the in line G, .') print('After the in line H, .') print('After the in line I, x = 61.0, y = 15, and z = 4.0.') print() print('-------------------------------------------------------------') print('2. Lists') print('-------------------------------------------------------------') ## 2.1. Print the value in each variable name using ONLY indices ## into numList. numList = [3,2,7,5] ## Here is an example. shouldBe1 = numList[0]-numList[1] print('An example: shouldBe1 =',shouldBe1) ## Replace the 0's with expressions that only use indices and operators. shouldBe4 = 0 print('shouldBe4 =',shouldBe4) shouldBe10 = 0 print('shouldBe10 =',shouldBe10) shouldBe20 = 0 print('shouldBe20 =',shouldBe20) shouldBe25 = 0 print('shouldBe25 =',shouldBe25) ## 2.2. Put the classes you are currently taking into the ## mySchedule variable. mySchedule = ['bio131'] ## 2.2(a) Print the length of mySchedule ## 2.2(b) Print the first and last items of mySchedule ## 2.2(c) Try the following line: print(mySchedule[len(mySchedule)]). ## What happens? Write your answer in the comments. ## 2.3. The range() function. print() print('Practice with the range() function.') ## 2.3(a) evaluate the following expressions. #print(list(range(5))) #print(list(range(10))) #print(list(range(1))) ## 2.3(b) Use the range() function to print the indices of mySchedule. print() print('-------------------------------------------------------------') print('3. FOR Loops') print('-------------------------------------------------------------') print() ## 3.1. Print the elements of numList: ## 3.2. Print the elements of mySchedule: ## 3.3. Use a for loop to print the index of each element of mySchedule. ## Modify the code to print the value and the length as well. ## 3.4. Use a for loop to count the number of elements. numClasses = 0 ## print('numClasses:',numClasses) print('-------------------------------------------------------------') print('4. Write a Change Counter') print('-------------------------------------------------------------') ## coinDenominations contains four values: one each for a ## penny, a nickel, a dime, and a quarter. coinDenominations = [1,5,10,25] print('coinDenominations:',coinDenominations) ## numberOfCoins contains four values: the number of pennies, nickels, ## dimes, and quarters you find in your pocket. You may have 0 coins of some ## denomination. numberOfCoins = [3,1,0,2] print('numberOfCoins',numberOfCoins) ## dollarAmount is the number of dollars you have. dollarAmount = 0 ## ## print the dollar amount. print('The dollar amount is: $',dollarAmount) print('-------------------------------------------------------------') print('5. String Slices') print('-------------------------------------------------------------') ## Evaluate the lines from the instructions. stringOfNumbers = '0123456789' print(stringOfNumbers) print('-------------------------------------------------------------') print('6. Hypothetical Gene') print('-------------------------------------------------------------') hypotheticalgene = 'eeeeeeeeeeeiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiieeeeeee' print('\nhypothetical gene:',hypotheticalgene) ## These variables represent the index of the start of each exon, the ## intron, and the length of the gene. exon1start = 0 intron1start = 11 exon2start = 43 genelen = len(hypotheticalgene) ## 6.1. Print the lengths of the exons using the start and genelen variables ## 6.2. Store strings corresponding to the exons and the intron. ## Assign variables to strings that correspond to exon1, exon2, and the intron. ## 6.3. Print the length of hypotheticalgene and the sum of the exons + intron. #print('-------------------------------------------------------------') #print('7. Extra Exercises (Optional)') #print('-------------------------------------------------------------') ## Exon Starts and Intron Starts as lists ## Exon/Intron Starts for the SRC Gene SRCexonstarts = [0,1546,3471,11291,11570,13558,15095,17511,18998,19831,20145,20567] SRCintronstarts = [183,1800,3571,11390,11674,13708,15251,17691,19075,19985,20277,22829] ## When you're done, uncomment the line below. #print('Done with HW2!') print() print('When you\'re done, write the approximate amount of time spent in the comments.') ## Approximate Time Spent: