TCSS142 Computer Science and Systems

Added on - Sep 2019

Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 3 of 8 pages
TCSS142REVIEW QUESTIONS1REVIEW QUESTIONS1) String ManipulationCorrect the following:print(“”This is a test,\” said the teacher\’s assistant, ”of “ +“what you \”know about backslash \ characters.’)Write code to change the line, “Bilbo Baggins and Gandalf the Greywere old friends.”, so thatAll the consonants are capitalizedAll the vowels are removedAll the capital letters replaced by their ASCII valuesThere are no duplicate letters (case ignored)The string is reversed character-by-characterThe string is sorted by word in alphabetical orderChange your above code so that it is robust (any string could be inputand the output will be correct); you should probably use for loops.Write a program that takes user input as a string and then prints outthat string with every word backwards (a word as defined by anysequence of characters separated by a space).2) File Reading and WritingWrite a program that reads a file filled with one month and year perline (e.g., “March 2004”, “February 2000”) and prints to the consolethe number of days in that month (e.g., “31 days in March 2004”). Youshould use nested conditionals and have your program correctly reportleap years’ differing February days using the rules according toWikipedia.
TCSS142REVIEW QUESTIONS2Write a program that can write to a file from another file, eachspecified as entry from the console. (Use any of the text filesprovided you from this course or make your own.) From the file beingread, you should iterate over each line and character, passing onlypunctuation, numbers, and the letters ‘p’, ‘y’, ‘t’, ‘h’, ‘o’, and ‘n’to the file being written to.Write a program that reads a file and counts up how many of each typeof ASCII value appears throughout the file. Print this out as a tableusing tabs to format it.3) Tracing, Scope, and Pre/PostconditionsGiven the following code, expand the table below recording all of thevariable values every time a variable changes:i = 100j = 0h = 4000while i >= j:j = ih = i * 50while j > 5:j -= 20while h > i:h /= 10i += 1.5i -= 32.5Variable Changeijhi100j1000h10004000............For the following code, record the value of a every time it changes:a = 1while (a < 100):a *= 4a -= a // 2
TCSS142REVIEW QUESTIONS3Given the following code, trace the code line by line for eachfunction, using the table below as a model:def method1(d, c, b, a):print(a, b, c, d)d *= len(b)c += '5'b += [d, a]a = d < sum(b)print(a, b, c, d)def method2(w, x, y, z):print(w, x, y, z)w = w != wx = yy = zz = x * 3print(w, x, y, z)method3(z, z, y, z)def method3(h, i, j, k):print(h, i, j, k)h = 10i += ' word'j = [h, h, i, k]k *= 2print(h, i, j, k)def main():a = 15b = 'the'c = [2.0, 3.1, 4.2]d = Trueprint(a, b, c, d)method1(a, b, c, d)method2(d, c, b, a)method3(a, b, b, a)print(a, b, c, d)main()FunctionLine NumberVariable Names and Valuelist contentsmain11, 2, 3, 42a = 155, 6, 7, 83a = 15, b = ‘the’4a = 15, b = ‘the’, c =5a = 15, b = ‘the’, c = , d = Truemethod11d = 15, c = ‘the’, b = , a = True.........
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access