Docsity

MCS 260 L-16: Python, Algorithms, and Logic Gates - Prof. Jan Verschelde, Study notes of Computer Science

Partial preview of the text

Download MCS 260 L-16: Python, Algorithms, and Logic Gates - Prof. Jan Verschelde and more Study notes Computer Science in PDF only on Docsity!

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

Review I

1 Policies & Material

2 General Questions

3 Python code and Flowcharts

4 Circuits and Logic Gates

5 Functions

6 Summary

MCS 260 Lecture 16 Introduction to Computer Science Jan Verschelde, 1 October 2008

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

Policies

first midterm on Friday 3 October

Like quizzes, the exams are open book and open notes. In contrast to quizzes, calculators or laptop computers are not allowed. The policy on skipping exams is: If an exam is missed, then greater weight will be placed on the final exam, especially on the material covered on the missing exam. What this means is that if you decide not to take one midterm exam, your final exam will be weighted for one hundred points more. What it does NOT mean is that you can drop the score of a midterm exam. If you take the midterm, then your score counts. So, please be prepared when you show up for the exam.

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

General Questions

1 List the characteristics of an algorithm. Answer: precise and detailed enough to be implemented by a computer. 2 How many bytes are 15 terabytes? Answer: 1012 bytes. 3 Explain the difference between 34/87 and 34.0/87. Answer: 34/87 gives the integer division, whereas 34.0/87 returns a float. 4 What is an interrupt? Answer: an interrupt causes an executing process to go in waiting or ready state.

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

General Questions

1 List the characteristics of an algorithm. Answer: precise and detailed enough to be implemented by a computer. 2 How many bytes are 15 terabytes? Answer: 1012 bytes. 3 Explain the difference between 34/87 and 34.0/87. Answer: 34/87 gives the integer division, whereas 34.0/87 returns a float. 4 What is an interrupt? Answer: an interrupt causes an executing process to go in waiting or ready state.

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

General Questions

1 List the characteristics of an algorithm. Answer: precise and detailed enough to be implemented by a computer. 2 How many bytes are 15 terabytes? Answer: 1012 bytes. 3 Explain the difference between 34/87 and 34.0/87. Answer: 34/87 gives the integer division, whereas 34.0/87 returns a float. 4 What is an interrupt? Answer: an interrupt causes an executing process to go in waiting or ready state.

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

General Questions

1 List the characteristics of an algorithm. Answer: precise and detailed enough to be implemented by a computer. 2 How many bytes are 15 terabytes? Answer: 1012 bytes. 3 Explain the difference between 34/87 and 34.0/87. Answer: 34/87 gives the integer division, whereas 34.0/87 returns a float. 4 What is an interrupt? Answer: an interrupt causes an executing process to go in waiting or ready state.

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

Coin Change in Python

answer to question 5

x = input(’give a number : ’) m = x q = m/25 # number of quarters m = m%25 # rest of money d = m/10 # number of dimes m = m%10 # rest of money n = m/5 # number of nickels p = m%5 # number of pennies print ’$0.%d is
#quarters = %d, #dimes = %d,
#nickels = %d, #pennies = %d’ % (x,q,d,n,p)

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

Coin Change in Python

answer to question 5

x = input(’give a number : ’) m = x q = m/25 # number of quarters m = m%25 # rest of money d = m/10 # number of dimes m = m%10 # rest of money n = m/5 # number of nickels p = m%5 # number of pennies print ’$0.%d is
#quarters = %d, #dimes = %d,
#nickels = %d, #pennies = %d’ % (x,q,d,n,p)

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

6. How Circuits Work

Consider the circuit shown below. For b 1 1 and b 2 0 as input, indicate on the picture below the input and output for every logical gate.

 

 

 

 

C

S









b 2

b 1





Answer:

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

6. How Circuits Work

Consider the circuit shown below. For b 1 1 and b 2 0 as input, indicate on the picture below the input and output for every logical gate.

 

 

 

 

C

S









b 2

b 1





Answer:

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

7. Flowchart of a Search

Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers.

Answer: n len L   m L  0  ; i 1

 

 (^)   

^ i^^  n ? 

^ True

False  print m

 

 (^)    L  i (^)  m ?

^ True

False

m L  i 

i i 1

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

7. Flowchart of a Search

Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers.

Answer: n len L   m L  0  ; i 1

 

 (^)   

^ i^^  n ? 

^ True

False  print m

 

 (^)    L  i (^)  m ?

^ True

False

m L  i 

i i 1

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

7. Flowchart of a Search

Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers.

Answer: n len L   m L  0  ; i 1

 

 (^)   

^ i^^  n ? 

^ True

False  print m

 

 (^)    L  i (^)  m ?

^ True

False

m L  i 

i i 1

1 Oct 2008

Policies & Material General Questions Python code and Flowcharts Circuits and Logic Gates Functions Summary

7. Flowchart of a Search

Draw the flowchart for the algorithm to search for the maximum in a list of unsorted numbers.

Answer: n len L   m L  0  ; i 1

 

 (^)   

^ i^^  n ? 

^ True

False  print m

 

 (^)    L  i (^)  m ?

^ True

False

m L  i 

i i 1