Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives: Investigation, comparison and critique of features in the programmin

ID: 3914608 • Letter: O

Question

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 ttp://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:

a. Write a short program or programs to investigate its use. You may combine more than one feature into a single program.
b. Explain how the feature works in Python and compare it to one or more languages with which you are familiar.
c. 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.

Explanation / Answer

1. Interpretation:
a)An interpreted language either doesn’t have any compilation at all, or compiles to an intermediate representation, like bytecode. Bytecode is instructions for a virtual machine, not a piece of hardware. Python falls into this latter category: the Python compiler’s job is to generate bytecode for the Python interpreter.
b)You sometimes hear interpreted language instead of dynamic language which is usually, mostly same.

2.Boolean Expression & Short-circuit evaluation:

Short-circuit evaluations
To speed up boolean evaluations, Python uses short-circuit evaluations. It means that boolean evaluation may stop if one of its expression is False.
E.g.,For instance the following expression is always False
False and X
and X is never evaluated.

3.List:
A list is a collection which is ordered and changeable. In Python lists are written with square brackets.
e.g.,newlist = ["first", "second"]
print(thislist)

Tuples:A tuple is a collection which is ordered and unchangeable. In Python tuples are written with round brackets.
e.g,thistuple = ("cricket", "football")
print(thistuple)

Dictionary:
A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.
e.g,thisdict ={
"cricket": "sachin",
"football": "messi",
"chess": "anadh"
}
print(thisdict)

loops: program examples

1)i = 1
while i < 6:#with the while loop we can excute a set of statements as long a condition true
print(i)

2)fruits = ["apple", "banana", "cherry"]

for x in fruits:
  
if x == "banana":
  
continue
  
else:

print("print")

python indentation:

Python Indentations
Where in other programming languages the indentation in code is for readability only, in Python the indentation is very important.

Python uses indentation to indicate a block of code.

Example
if 5 > 2:
print("Five is greater than two!")#note the spaces

Python will give you an error if you skip the indentation:
Example
if 5 > 2:
print("Five is greater than two!")

Functions:
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.

Creating a Function
In Python a function is defined using the def keyword:

Example
def my_function():
print("Hello from a function")