Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris

Similar presentations


Presentation on theme: "COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris"— Presentation transcript:

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

2 FIRST REVIEW SESSION

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

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

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

6 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

7 Answer a b c

8 Third Question What characterizes a von Neumann computer?

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

10 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?

11 Answer (a)I do not have any great example (a)Your PC: interactive but not shared

12 Fifth Question What is the most likely reason your computer takes so much time to boot?

13 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

14 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?

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

16 Seventh Question Describe a practical heuristic for the same problem Why is it a heuristic?

17 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

18 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?

19 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)

20 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” _________

21 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)____

22 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?’)

23 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

24 Eleventh Question What will the following Python program print? – code = 5 if code == 1 print(“Hello!”) print(“Goodbye!”)

25 Answer The interpreter will catch the missing semicolon but – code = 5 if code == 1 : print(“Hello!”) print(“Goodbye!”) will print Goodbye!

26 Twelfth Question Write a Python program prompting for two floating point numbers and computing their average

27 What we need to do Prompt for first number, read it and convert to float Compute average Display average with 3 decimals

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

29 Thirteenth Question What 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 == c a = _________b = _________ c = _________d = _________

30 Answer a = 4 * 2 – 0.5 b = 2 c = a // b d = a == c a = ___7.5___b = ___2_____ c = ___3_____d = __False____

31 Fourteenth Question What is wrong with the following Python code? – i = 1 while i > 0 : print(“Going though the loop!”) i = i + 1

32 Answer The program – i = 1 while i > 0 : print(“Going though the loop!”) i = i + 1 will never end as the variable i is incremented instead of being decremented

33 Fifteenth Question What is wrong with the following Python code? – i = 5 while i > 0 : print(“Going though the loop!”) i = i - 1

34 Answer The program – i = 5 while i > 0 : print(“Going though the loop!”) i = i - 1 will never end as the variable i is not decremented inside the loop


Download ppt "COSC 1306 COMPUTER LITERACY FOR SCIENCE MAJORS Jehan-François Pâris"

Similar presentations


Ads by Google