final exam.py
Document Details

Uploaded by WellRunJaguar6742
University of Central Florida
Full Transcript
Sample Questions: Function calls ============== def question(x, y): while (x != y): if (x\>y): x-=2 else: y-=1 return x + y What is the value of question(5, 2)? Work: x = 5 -\> 3 -\> 1 y = 2 -\> 1 answer is 2 What are valid function calls to the function above? - q(4, 3) \24 index = 0-\>1-\>2...
Sample Questions: Function calls ============== def question(x, y): while (x != y): if (x\>y): x-=2 else: y-=1 return x + y What is the value of question(5, 2)? Work: x = 5 -\> 3 -\> 1 y = 2 -\> 1 answer is 2 What are valid function calls to the function above? - q(4, 3) \24 index = 0-\>1-\>2 items = \[\] for r in range(4): row = \[\] for c in range(2): if (r==c): row.append(-1) else: row.append(r+c) items.append(row) What is the list (items) store at the end of the program? ========================================================= r=3 === c=1 === row: \[3, 4\] ============= \[\[-1, 1\], \[1,-1\], \[2,3\], \[3, 4\] \] word = "Rubber Duck" What prints out of word\[:3\]? "Rub" How many characters does word\[:3\] print out? 3 What prints out of word\[2:9\]? "bber Du" How many characters does word\[2:9\] print out? 7 What prints out of word\[-3:\]? "uck" How many characters does word\[-3:\] print out? 3 word = "Rubber Duck" new\_word = \"\" for letter in word: if letter=="u": new\_word += "UCF" else: new\_word += letter print(new\_word) What prints out? ================ new\_word = "RUCFbber DUCFck"