CS 3120 Homework 3 Due Tuesday May 2, 2017 at 11:59 PM CST Objectives: Investiga
ID: 3832993 • Letter: C
Question
CS 3120 Homework 3
Due Tuesday May 2, 2017 at 11:59 PM CST
Objectives:
Investigation, comparison and critique of features in the programming language
Python
.
Language:
Python is an interpreted, object-oriented programming language developed in 1990 by Guido
van Rossum, computer scientist at CWI in Amsterdam and
Monty Python
fan. Python is very
portable since Python interpreters are available for most operating system platforms. The latest
Python source distribution and Python documentation is available from python.org, at
http://www.python.org/
. Python is enough like languages you are familiar with to make it fairly
easy to learn, yet different enough to be interesting to study.
Assignment:
Investigate the following features or constructs as they pertain to Python:
1.
interpretation
2.
Boolean expressions
3.
short circuit evaluation
4.
numeric types
5.
strings
6.
arrays
7.
lists
8.
tuples
9.
slices
10.
index range checking
11.
dictionaries
12.
if statement
13.
switch statement
14.
for loop
15.
while loop
16.
indentation to denote code blocks
17.
type binding
18.
type checking
19.
functions
20.
one other feature - your choice
For each of the above features you should do the following:
1.
Write a short program or programs to investigate its use. You may combine more than
one feature into a single program.
2.
Explain how the feature works in Python and compare it to one or more languages with
which you are familiar.
3.
Critique the implementation or use of the feature or construct.
Note:
Some of the features above are not included in Python, in which case you should note
that they are missing and critique the decision to leave them out.
Finally, you should give an overall critique of Python.
What to Hand In:
You need to include:
The source code files for all of your Python programs.
A copy of the output from all of your Python programs.
Your
typed
explanations and critiques. Be sure to turn in both a critique of each feature
and an overall critique of the Python language.
If you wish, you may write a single program that utilizes all of the applicable features above.
However, at each point you are demonstrating a feature, you should include a substantial
discussion in comment form explaining that feature and how it applies in Python.
Explanation / Answer
1.Interpretation : A high level language run and executed by an Interpreter
a program which converts the high-level language to machine code and then executing
It processes the program a little time.
2.Boolean expressions:
A Boolean value is either true or false.
A Boolean expression is that evaluates to produce a result which is a Boolean value.
3.Short circuit evaluation:
An operator is said to be short-circuit when it will stop evaluating
as soon as it reaches a definitive result. This is obvious for the OR operator, that
only needs one of its operands to be True to returns True
1 1+1 == 2 or 3**3 == 27 is true
OR will immediately stop the evaluation when the first operand is True.
Then this behavior is called short circuit evaluation.
4.Numeric types:
numeric types in python are int,float,long and complex.
complex numbers have real and imaginary part.
5.Strings:
Joining of two or more strings in to a single is called cocatenation.
6.Array:
An array is a data structure which stores values of same data type.
7.List:
List is a data type available in python.
In list is that items in a list need not be of same type.
8.tuples:
A tuple is immutable list.
a tuple does not change once we are created.
9.Slice
Slice object represents the indices specified by range(start, stop, step).
The syntax of slice() are:
slice(stop)
slice(start, stop, step)
10.index range checking
if the index want is in the range of 0 and the length of the list, like this
if 0 <= index < len(list):
11.Dictionary:
The values of a dictionary can be of any type,
but the keys must be of an immutable data type such
as strings, numbers, or tuples.
12.if statement:
In python if the conditional expression in the if statement resolves to 0 or a FALSE value.
13.Switch statement:
Switch statement is not present in python.
14.For loop:
For loops is iterate over a sequence of numbers that can using the "range" and "xrange" functions.
15.While loop:
A while loop statement in Python repeatedly executes a target statement as long as a given condition is true.
16.
indentation to denote code blocks;
one of the most distinctive feature of python is
used to indentation to mark blocks of code
but in python it is required for indicating
what block of code a statement belongs to.
17:
Type binding:
There are two types of binding.
Static and dynamic binding.
Static binding:
In static binding process is done just once, before execution.
Dynamic binding:
It is very easy to write generic code.
18.Type checking:
type-checking is convenient, easy to implement, and can save life when debugging.
19.Function:
A function is a block , reusable code that is use to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.
20.Free and open source:
python is a free and open source .It has freely distributed copies of software .