Enabled: Statistics Tracking
Due 11/20, Friday, 11:59PM.
1. Describe how subprograms work.
2. Define a function in python named c_double(x): give a value x, and the function will return a doubled value, for example, if x = 1, the result will be 2; if x = 3, the result will be 6. Write a program to call the function to calculate the result for x = 1, 2, 3, 4, 5.
Due 11/13, Friday, 11:59PM.
Please write a python program as10.py to have the following function:
Once the program runs, it will show the information:
Please input a grade:
If you input a number less than 60, it will print out information:
Bad grade, you can not pass!
If you input a number grater than 60, it will print out information:
Congratulations! You passed!
Please submit the as10.py as an attachment.
Due 11/6, Friday, 11:59pm
Give examples to present the following statements in Python:
1. Selection statement with 2-way selectors.
2. Selection statement with multiple-way selectors.
3. Iterative statement.
4. Unconditional branching.
Enabled: Statistics Tracking
Due 10/30, Friday, 11:59pm.
1. Give an example of arithmetic expression in python.
2. List operators for arithmetic expressions in python.
3. Give an example of rational/boolean expression in python.
4. List operators for rational/boolean expression in python.
5. Is there any type conversion in the following expression, and why?
9 / 3.0
Enabled: Statistics Tracking
Due 10/23, 11:59pm, Friday.
1. What is array?
2. Read python reference and describe how to present an array in python.
3. Write down the source code to define an array {1, 3, 5, 7, 9} in python.
Enabled: Statistics Tracking
Due 10/16, Friday.
Figure out how to write a python program and run it.
You will need to submit a simple python program as an attachment, the output of the python program should be:
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
Sample questions for Midterm Exam. Due 10/2, Friday.
Enabled: Statistics Tracking
Due 9/25, Friday, 11:59pm.
1. Define data type.
2. Check the language reference of Python, list primitive data types in python.
3. Type the following commands in python and find out the outputs. (You can download portable python to your flash drive from http://www.portablepython.com/, then you can bring it to any lab, and practice python programing anywhere.)
1) type(True)
2) type("Hello, this is new file.")
3) type(98037843907273829071840782197)
4) type(9)
5) type(9.0)
(You may need to use print type( ) instead of type( ).)
Enabled: Statistics Tracking
Due 9/18, Cover Chapter 5.
1. Define type checking, compatible type and type error.
2. What is scope of a variable? What kind of variable is visible variable?
3. Check 3.2 of the language reference of Python, is the type int and bool compatible? Why?
4. Read 4.1 of the language reference of Python, what is the scope of a in the following code? Why the following code will fail?
class A :
a = 42
b = list ( a + i for i in range ( 10 ))
Enabled: Statistics Tracking
Due 9/11, Cover Chapter 5. We will also use programming language Python to teach you how to learn a new language quickly.
1. Check the link: http://docs.python.org/3.1/index.html and click Language Reference. Read 1.2. Notation.
Based on:
name ::= lc_letter (lc_letter | "_")*
lc_letter ::= "a"..."z"
a. in above grammar, what are terminals and what are non-terminals?
b. In the following strings, which is/are acceptable notation(s)?
a) ab b) Tab c) ab_c d) ab12 e) ab_12 f) _ab
2. What are the design issues for names?
3. Define binding, binding time, static binding and dynamic binding.
Assignment 3: Context-Free Grammar
Item is no longer available. It was last available on Sep 4, 2009 11:59 PM.
Enabled: Statistics Tracking
Due 9/4.
1. Given grammar:
<program> → <stmts>
<stmts> → <stmt> | <stmt> ; <stmts>
<stmt> → <var> = <expr>
<var> → a | b | c | d
<expr> → <term> + <term> | <term> - <term>
<term> → <var> | const
Write down derivation of:
b = a - c
(Hint: check sample of p13 of Lecture 2)
2. What is ambiguous in a grammar?
Assignment 2: Syntax / Semantics (1)
Item is no longer available. It was last available on Aug 28, 2009 11:59 PM.
Enabled: Statistics Tracking
Due 8/28 11:59pm. Cover Chapter 2 / Lecture 2. Click above link to do the assignment.
Item is no longer available. It was last available on Aug 28, 2009 11:59 PM.
Enabled: Statistics Tracking
Due 8/28 11:59pm. Cover Chapter 1 / Lecture 1. Click above link to do the assignment.