Docsity

Homework 1 with 6 Problems - Introductory Programming | EECS 12, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
EECS12 Homework #1 Due: 11:59 PM, Thursday, January 13, 2005
For this assignment you are to create a plain text file called hw1.txt which is to contain answers
to each of the following questions; please remember to clearly label each problem. (You can use
Notepad,emacs, or any other text editor you are familiar with to create and edit the hw1.txt file.)
For the first several problems you need only indicate that the task has been successfully performed,
or explain any problems that prevented you from doing so. For the remaining problems you are to
provide code and/or written answers. You are to submit this file electronically. (Instructions will
be provided on the news and the policies page shortly.)
1. Fill out the Student Contract that is available on the downloads page of the class web site
(http://www.ics.uci.edu/~arvo/EECS12), and mail it back to one of the TAs. The contract
contains full instructions.
2. Read chapters 1 and 2 in How to Think Like a Computer Scientist, which is available on the
downloads page of the class web site.
3. Gain access to a computer that has the Python programming language installed. (All the
computers in the lab for this class, room 123 of the Engineering and Computing Trailer (ECT),
have Python installed, but you are free to use any machine you wish. For example, you can
install Python on your personal machine for free from the web site http://python.org/)
Start the Python interpreter (either the graphical user interface for Python called IDLE, or
the standard Python command line interface) and try some of the examples that are discussed
inchapters1and2ofHow to Think Like a Computer Scientist. (Do more if you are so
inspired.)
4. For the following questions you may need to consult various references (such as those listed
on the downloads page), perform a Google search, etc. If your answers are very unusual (and
therefore not recognized by the grader), you may be asked to provide a reference to back up
your answer.
(a) List four well-known computer languages that are compiled but (generally) not inter-
preted.
(b) List four well-known computer languages that are interpreted (whether or not they can
also be compiled).
(c) List four well-known computer languages that are considered to be object oriented.
5. For each of the following, include the Python code in your file along with any requested
explanation.
(a) Construct a tiny Python program that contains a syntax error due to an incorrect token.
Describe what Python prints in response.
(b) Construct a tiny Python program that contains a syntax error due to a grammatical error;
i.e. tokens that are not ordered corretly. Describe what Python prints in response.
(c) Construct a tiny Python program that contains a semantic error; i.e. a program that runs
but does not do what it is “intended” to do. (Of course, you will need to describe what
the “intention” was, and what the program does instead.)
6. Copy SampleProgram1.py from the downloads page, and run the functions that are defined in
it. Select one of the functions and modify it to compute the sum
1+x+x2+x3+...+x20 (1)
and return the resulting value as the function’s value, where xis a variable that is passed in
as an argument to the function. Write another function, called “fraction,” that also accepts
a single argument and computes the value of the expression
1
1−x,(2)
1
pf2

Partial preview of the text

Download Homework 1 with 6 Problems - Introductory Programming | EECS 12 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

EECS12 Homework #1 Due: 11:59 PM, Thursday, January 13, 2005

For this assignment you are to create a plain text file called hw1.txt which is to contain answers to each of the following questions; please remember to clearly label each problem. (You can use Notepad, emacs, or any other text editor you are familiar with to create and edit the hw1.txt file.) For the first several problems you need only indicate that the task has been successfully performed, or explain any problems that prevented you from doing so. For the remaining problems you are to provide code and/or written answers. You are to submit this file electronically. (Instructions will be provided on the news and the policies page shortly.)

  1. Fill out the Student Contract that is available on the downloads page of the class web site (http://www.ics.uci.edu/~arvo/EECS12), and mail it back to one of the TAs. The contract contains full instructions.
  2. Read chapters 1 and 2 in How to Think Like a Computer Scientist, which is available on the downloads page of the class web site.
  3. Gain access to a computer that has the Python programming language installed. (All the computers in the lab for this class, room 123 of the Engineering and Computing Trailer (ECT), have Python installed, but you are free to use any machine you wish. For example, you can install Python on your personal machine for free from the web site http://python.org/) Start the Python interpreter (either the graphical user interface for Python called IDLE, or the standard Python command line interface) and try some of the examples that are discussed in chapters 1 and 2 of How to Think Like a Computer Scientist. (Do more if you are so inspired.)
  4. For the following questions you may need to consult various references (such as those listed on the downloads page), perform a Google search, etc. If your answers are very unusual (and therefore not recognized by the grader), you may be asked to provide a reference to back up your answer.

(a) List four well-known computer languages that are compiled but (generally) not inter- preted. (b) List four well-known computer languages that are interpreted (whether or not they can also be compiled). (c) List four well-known computer languages that are considered to be object oriented.

  1. For each of the following, include the Python code in your file along with any requested explanation.

(a) Construct a tiny Python program that contains a syntax error due to an incorrect token. Describe what Python prints in response. (b) Construct a tiny Python program that contains a syntax error due to a grammatical error; i.e. tokens that are not ordered corretly. Describe what Python prints in response. (c) Construct a tiny Python program that contains a semantic error; i.e. a program that runs but does not do what it is “intended” to do. (Of course, you will need to describe what the “intention” was, and what the program does instead.)

  1. Copy SampleProgram1.py from the downloads page, and run the functions that are defined in it. Select one of the functions and modify it to compute the sum 1 + x + x^2 + x^3 +... + x^20 (1) and return the resulting value as the function’s value, where x is a variable that is passed in as an argument to the function. Write another function, called “fraction,” that also accepts a single argument and computes the value of the expression 1 1 − x

which it returns as its function value. Verify the values returned for both functions are very close to one another for positive values of x that are strictly less than 1. (What happens when x > 1?)

Please remember to include the standard six-line header at the top of your hw1.txt file!