COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris email@example.com
Post on 11-Jan-2016
Embed Size (px)
COSC 1306COMPUTER LITERACY FORSCIENCE MAJORSJehan-Franois Prisjfparis@sbcglobal.net
FIRST REVIEW SESSION
First QuestionWe saw in class that Pascals calculating machine was not a commercial success. Why does it remain important?
AnswerIt showed that adding/subtracting machines could be built:Proof of concept
Second QuestionImplement the Boolean function a and (b or c) using switches assuming that closed switches correspond to true values.
AnswerTip:When you see an and, put the switches in series (one after the other)When you see an or, put the switches in parallel
Third QuestionWhat characterizes a von Neumann computer?
AnswerA von Neumann computer has a memory in which it stores both its programs and its data
Fourth QuestionCan you find examples of (a) a time-sharing system that is not interactive and (b) an interactive system that is not a time-sharing system?
AnswerI do not have any great example
Your PC: interactive but not shared
Fifth QuestionWhat is the most likely reason your computer takes so much time to boot?
AnswerIt has to bring too many things in main memoryThe kernelAll the other programs that are set to be loaded in main memory a boot timeOften junkware
Sixth QuestionYou are going to the University Center with a nerd who claims he has an algorithm for finding out what is the best available flavor at the ice cream shop. Can you guess his algorithm?
AnswerGetting samples of all flavors being offered that day before making a decision
Seventh QuestionDescribe a practical heuristic for the same problemWhy is it a heuristic?
AnswerThinking of your favorite flavors and maybe asking for a sample of an interesting flavor
You are very likely to get a flavor you will like but could have missed an even better tasting flavor
Eighth QuestionYou have to search for an item in a list of 20 of them.Does it make a big difference if you use linear search or binary search?Would it be true for a list of 50,000 items?
AnswerNo, it would not make a big difference for a list of 20 itemsLinear search is the best solutionSimplerYes, it would make a big difference for a list of 50,000 itemsBinary search is the best solutionMuch faster (average of 16 steps vs. 25,000)
Ninth QuestionWhich of the following items are (a) constants, (b) reserved words (c) variables and (d) expressions?3.5 _________elif _________ while _______44 _________ input/output _____ side-car _________ False ________rhubarb _________ '27 _________indeed _________
AnswerWhich of the following items are (a) constants, (b) reserved words (c) variables and (d) expressions?3.5 __(a)_____elif ___(b)_____ while __(b)____44 ___(c)______ input/output _(d)_ side-car __(d)____ False __(a)_____rhubarb __(c)____ '27 ____(a)____indeed __(a)____
Tenth QuestionWhat is probably wrong with the following Python code?
nfingers = input(How many fingers do you have?) if nfingers != 20 : print(Did you lose some in an accident?)
AnswerTwo thingsThe string in the second print statement is not properly terminatedWill be caught by interpreterWe compare a string value with an integer constantNot caught by interpreter
Eleventh QuestionWhat will the following Python program print?code = 5 if code == 1 print(Hello!) print(Goodbye!)
AnswerThe interpreter will catch the missing semicolon butcode = 5 if code == 1 : print(Hello!) print(Goodbye!)will print Goodbye!
Twelfth QuestionWrite a Python program prompting for two floating point numbers and computing their average
What we need to doPrompt for first number, read it and convert to floatPrompt for first number, read it and convert to floatCompute averageDisplay average with 3 decimals
Answer# average.py a = float(input("Enter first number: ")) b = float(input("Enter second number: ")) average = (a + b)/2 print(Average is %.3f" % average)
Thirteenth QuestionWhat are the values of the variables a, b, c, d after the following Python code is executed? a = 4 * 2 0.5 b = 2 c = a // b d = a == ca = _________b = _________ c = _________d = _________
Answera = 4 * 2 0.5 b = 2 c = a // b d = a == ca = ___7.5___b = ___2_____ c = ___3_____d = __False____
Fourteenth QuestionWhat is wrong with the following Python code?i = 1 while i > 0 : print(Going though the loop!) i = i + 1
AnswerThe programi = 1 while i > 0 : print(Going though the loop!) i = i + 1will never end as the variable i is incremented instead of being decremented
Fifteenth QuestionWhat is wrong with the following Python code?i = 5 while i > 0 : print(Going though the loop!) i = i - 1
AnswerThe programi = 5 while i > 0 : print(Going though the loop!) i = i - 1will never end as the variable i is not decremented inside the loop