Chota Abd
Chota Abd
Objective:
Tools/Software Requirement
Python 3.0
Theory
Introduction to MATLAB
Compiler and Interpreter are two different ways to execute a program written in a programming or
scripting language.
Compiler:
❖ The language processor that translates the complete source program as a whole in machine code
before execution is called compiler.
❖ The C and C++ compilers are best examples of compilers.
❖ The program translated into machine code is called the object program.
❖ The source code is translated to object code successfully if it is free of errors.
❖ If there are any errors in the source code, the compiler specifies the errors at the end of
compilation.
❖ The errors must be removed before the compiler can successfully compile the source code.
Interpreter:
❖ The language processor that translates (converts) each statement of source program into machine
code and executes it immediately before to translate the next statement is called Interpreter.
❖ If there is an error in the statement, the interpreter terminates its translating process at that
statement and displays an error message.
Python uses both processes, but because of the way programmers interact with it, it is usually considered
an interpreted language. There are two ways to use the Python interpreter: shell mode and script mode.
In shell mode, you type Python statements into the Python shell and the interpreter immediately prints the
result.
In script mode, you type statements into the editor and save it in a file known as script. The interpreter
executes the code of the script.
i. Running Python Interpreter:
Python comes with an interactive interpreter. When you type python in your shell or command prompt,
the python interpreter becomes active with a >>> (REPL) and waits for your commands.
Fig. 1.3 IDE Shell First Look
Now you can type any valid python expression at the prompt. Python reads the typed expression,
evaluates it and prints the result.
IDLE is the standard Python development environment. Its name is an acronym of "Integrated
Development Learning Environment". It works well on both Unix and Windows platforms. It has a
Python shell window, which gives you access to the Python interactive mode. It also has a file editor that
lets you create and edit existing Python source files.
Go to File menu click on New File (CTRL+N) and write the code and save abc.py. Then run the program
by pressing F5 or Run ==> Run Module
Fig. 1.5 Run Module in IDLE Window
Python print() function prints the message to the screen or any other standard output device.
Syntax:
print(value(s), sep= ' ', end = '\n')
Parameters:
value(s): Any value, and as many as you like. Will be converted to a string before printed
sep=’separator’ : (Optional) Specify how to separate the objects, if there is more than one
end=’end’: (Optional) Specify what to print at the end.
Return Type: It returns output to the screen.
# This print() function ends with "**" as set in the end argument.
print ("Python is the best ", end= "**")
print("Welcome to IDLE")
a=12
b=12
c=2022
print(a,b,c,sep="-")
Single line comments: Python single-line comment starts with a hashtag symbol with no white spaces
(#) and lasts till the end of the line. If the comment exceeds one line then put a hashtag on the next line
and continue the comment.
Multi-line string as a comment: Python multi-line comment is a piece of text enclosed in a delimiter
(“””) on each end of the comment. Again there should be no white space between delimiter (“””). They
are useful when the comment text does not fit into one line; therefore need to span across lines.
print("ABCD")
Lab Task:
Write a code in Python which takes user input for name, registration ID and email address and display the
responses as three different display formats.
Codes:
Evaluation Criteria:
Un- Developing Satisfactory Good Exemplary Marks
satisfactory (2) (3) (4) (5)
(0-1)
Does not Completed
comply with less than 75%
Completed at Completed
requirements of the Completed
least 75% of between 80-
(does requirements 100% of
the 99% of the
something . requirements
requirements requirements
Organization other than . Code
Not delivered . .
requirements) appears
/ Structure on time or
. Delivered on Code lacks finished and
not in correct
time, and in some minor organized
Information is format (disk,
correct structural properly
presented in a email,
format. continuity.
very mundane Canvas,
way printout etc.)
Poorly Unclear OR
States explicit
Respective written inaccurate
Correct logic results of a
Code and program results due to
but produces program in
Results and result does with faulty minor
no result due accordance
Conclusion not logic and programming
to an error in with the
complement syntax, logic
the code programming
each other producing negligence or
logic
wrong result. syntax error.
Lab Instructor: Lec. Faria Tasneem Sheikh/Lab Engr. Wahaj Rafique Total