Additional Practice Questions

docx

School

University of Alberta *

*We aren’t endorsed by this school

Course

101

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

6

Uploaded by DrCloverPorcupine11

Report
Additional Practice Questions from Final Exams 2019 - 2021 Question 1 : 1) Convert the following binary numbers to decimal (i.e., convert base 2 to base 10). 11101 = 10100 = 2) Convert each of the following decimal numbers to binary (i.e. convert based 10 to base 2). 16 27 3) Complete the following binary addition: 1 1 1 1 1 + 1 1 1 0 1 4) Complete the following binary multiplication: 1 1 1 1 0 x 1 0 1 5) Using the sum of products, derive the expression E from the following truth table: P R E 0 0 0 0 1 0 1 0 0 1 1 1 E = 1
Question 2 : Trace through the following program, and fill out the tables below. def sequentialSearch(alist, item): i = 0 found = False outlist = [0] * 10 while i < len(alist): if alist[i] == item: outlist[i] = 1 found = True i = i + 1 print(outlist) return found mylist = [12, 2, 32, 5, 17, 12, 12, 13, 4, 12] print(sequentialSearch(mylist, 1)) outlist found print(sequentialSearch(mylist, 12)) outlist found What is this sequential search program doing? Complete the below function count( ) that will count the number of occurrences of item . The function takes outlist as a parameter, and returns the number of occurrences of item . The function count( ) can be called from the above sequential search function. def count (outlist): occurrences = 0 2
return occurrences Question 3 : Trace through the following program by creating your own trace table and showing the outputs of the program when the input is 12. def convert(number): bits = [] while number > 0: remainder = number % 2 bits.append(remainder) number = number // 2 return bits def format(list): binStr = '' i = len(list)-1 while i >= 0: binStr = binStr + str(list[i]) i = i – 1 return binStr # main decimal = int(input("Enter a positive integer:")) bits = convert(decimal) binary = format(bits) print("The binary of", decimal, "is", binary) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Question 4 : Trace through the following Python program and fill the table below: def printNum(alist): newList = [] for i in range(len(alist)): if i % 2 != 0: newList.append(alist[i]) return newList myList = [3,5,8,9,12,15,18] print(printNum(myList)) i i%2 != 0 newList What are the final outputs of this program? What’s the purpose of this program? What does it print? 4
Question 5 : Trace through the following Python program, and fill in each box below with the output of each print statement preceding an empty box. You may assume the user will enter the following input: Daniel , Mikail , Smith , for first, middle, and last names respectively. def f_one(a, b, c): return a[0] + '. ' + b[0] + '. ' + c[0] + '.' def f_two(a, b, c): return a + ' ' + b + ' ' + c def f_three(s): return (s + ' ') * (len(s)//2) def f_four(s, ch): count = 0 for i in range(len(s)): if ch == s[i]: count = count + 1 return count # main program first = input('Enter your first name: ') middle = input('Enter your middle name: ') last = input('Enter your last name: ') print(f_one(first, middle, last)) print(f_two(first, middle, last)) print(f_three(first)) full_str = f_two(first, middle, last) print(f_four(full_str, 'i')) 5
6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help