34
COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris [email protected]

COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris [email protected]

Embed Size (px)

Citation preview

Page 1: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

COSC 1306COMPUTER LITERACY FOR

SCIENCE MAJORS

Jehan-François Pâ[email protected]

Page 2: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

FIRST REVIEW SESSION

Page 3: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

First Question

• We saw in class that Pascal’s calculating machine was not a commercial success. Why does it remain important?

Page 4: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• It showed that adding/subtracting machines could be built:– Proof of concept

Page 5: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Second Question

• Implement the Boolean function a and (b or c) using switches assuming that closed switches correspond to true values.

Page 6: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• Tip:– When you see an and, put the switches in

series (one after the other)– When you see an or, put the switches in

parallel

Page 7: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

a

b

c

Page 8: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Third Question

• What characterizes a von Neumann computer?

Page 9: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• A von Neumann computer has a memory in which it stores both its programs and its data

Page 10: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Fourth Question

• Can 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?

Page 11: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

(a) I do not have any great example

(a) Your PC: interactive but not shared

Page 12: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Fifth Question

• What is the most likely reason your computer takes so much time to boot?

Page 13: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• It has to bring too many things in main memory– The kernel– All the other programs that are set to be

loaded in main memory a boot time• Often junkware

Page 14: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Sixth Question

• You 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?

Page 15: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• Getting samples of all flavors being offered that day before making a decision

Page 16: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Seventh Question

• Describe a practical heuristic for the same problem

• Why is it a heuristic?

Page 17: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• Thinking 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

Page 18: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Eighth Question

• You 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?

Page 19: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• No, it would not make a big difference for a list of 20 items– Linear search is the best solution

• Simpler• Yes, it would make a big difference for a list of

50,000 items– Binary search is the best solution

• Much faster (average of 16 steps vs. 25,000)

Page 20: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Ninth Question

• Which 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” _________

Page 21: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• Which 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)____

Page 22: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Tenth Question

• What 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?’)

Page 23: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• Two things– The string in the second print statement is not

properly terminated• Will be caught by interpreter

– We compare a string value with an integer constant• Not caught by interpreter

Page 24: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Eleventh Question

• What will the following Python program print?– code = 5

if code == 1 print(“Hello!”)print(“Goodbye!”)

Page 25: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• The interpreter will catch the missing semicolon but

– code = 5if code == 1 : print(“Hello!”)print(“Goodbye!”)

will print Goodbye!

Page 26: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Twelfth Question

• Write a Python program prompting for two floating point numbers and computing their average

Page 27: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

What we need to do

• Prompt for first number, read it and convert to float

• Prompt for first number, read it and convert to float

• Compute average• Display average with 3 decimals

Page 28: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• # average.pya = float(input("Enter first number: "))b = float(input("Enter second number: "))average = (a + b)/2print(“Average is %.3f" % average)

Page 29: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Thirteenth Question

• What are the values of the variables a, b, c, d after the following Python code is executed?

• a = 4 * 2 – 0.5b = 2c = a // bd = a == c

• a = _________ b = _________c = _________ d = _________

Page 30: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• a = 4 * 2 – 0.5b = 2c = a // bd = a == c

• a = ___7.5___ b = ___2_____c = ___3_____ d = __False____

Page 31: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Fourteenth Question

• What is wrong with the following Python code?– i = 1

while i > 0 : print(“Going though the loop!”) i = i + 1

Page 32: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• The program

– i = 1while i > 0 : print(“Going though the loop!”) i = i + 1

will never end as the variable i is incremented instead of being decremented

Page 33: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Fifteenth Question

• What is wrong with the following Python code?

– i = 5while i > 0 : print(“Going though the loop!”)i = i - 1

Page 34: COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris jfparis@sbcglobal.net

Answer

• The program

– i = 5while i > 0 : print(“Going though the loop!”) i = i - 1

will never end as the variable i is not decremented inside the loop