You are on page 1of 8

21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

VIVA QUESTIONS & ANSWERS

UNIT -4

1.What is Python Language?


Python is an interpreted, object-oriented, high-level programming language with
dynamic semantics.
Python programming language is being used in web development, Machine Learning
applications, along with all cutting-edge technology in Software Industry

2. List out the features of Python?


Python is an open source language
Python programs are interpreted
It is portable, it means it executes all platforms
It is object oriented and has huge set of libraries

3.What are the execution mode of python?


• Interactive mode
• Script mode

4.What is Interactive Mode?


Interactive mode is a command line shell.
The user can execute commands and get the output immediately.
The commands are executed via the python shell, which comes with python
installation.

5.What are the advantages of Interactive Mode?


Helpful when your script is extremely short and you want immediate results.
Faster as you only have to type a command and then press the enter key to get the
results.
Good for beginners who need to understand Python basics.

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

6.What are the disadvantages of Interactive Mode?


Not suitable for large programs.
Not suitable for professional programmers.

7.What is Script Mode?


If we need to write a long piece of python program, script mode is the right option.
In script mode, we have to write a code in a text file then save it with a .py
extension which stands for python.

8.What are the advantages of Script Mode?


It is easy to run large pieces of code.
Editing your script is easier in script mode.
Good for both beginners and experts.

9.What are the disadvantages of Script Mode?


Can be tedious when you need to run only a single or a few lines of cod.
You must create and save a file before executing your code.

10.What is Colab?
Colaboratory, or “Colab” for short, is a product from Google Research.
Colab allows anybody to write and execute arbitrary python code through the
browser, and is especially well suited to machine learning, data analysis and
education.
More technically, Colab is a hosted Jupyter notebook service that requires no setup
to use, while providing access free of charge to computing resources including
GPUs.

11.What is the advantage of Colab over other online python compiler?


• Free to use GPU
• Cloud based
• Built in Library
• Easy collaborate the project

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

12.Mention the steps to use Google Colab.


Open Google Colab: https://colab.research.google.com/
Create a New Notebook
Run Your Code
Save Your Notebook

13.What are the basic data types in Python?


• Integer
• Float
• Boolean

14.What is String?
String is collection of characters. All string methods return new values.
They do not change the original string. Strings in python are surrounded by either
single quotation marks, or double quotation marks.

15.How to find the string length in python?


Using len( ) method
Syntax is len(string_variable)

16.Syntax for input statement


Variable_name = input(“prompt string”)
Ex. a= input(“Enter an integer”)

17.What is comment?
A comment is a piece of code that are not executed.
Comments are used to explain the source code and to make the code more readable
and understandable.
They are used for documentation purpose.

18.What are the types of comments?


• Single Line Comment ( # symbol)
• Multi Line Comment ( “”” …. “””)

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

19.What is Single Line Comment?


A single-line comment starts and ends in the same line.
# symbol is used for single line comments.
Example:
#This is a single line comment in python

20.What is Multi Line Comment?


Multiline comments are used for large text descriptions of code or to comment
out chunks of code while debugging applications.
“”” ….. “””” Triples quotes are used.
Example:
“”” This is a example for
Multi line comment “””

21.What is error?
Errors are problems that occur in the program due to an illegal operation performed
by the user or by the fault of a programmer, which halts the normal flow of the
program.
Errors are also termed bugs or faults. There are mainly two types of errors in python
programming.

22.What are the types of error?


• Syntax error (compile time error)
• Exception (run time error) or (Logical error)

23.What is Syntax error?


Whenever we do not write the proper syntax of the Python programming language (or
any other language) then the python interpreter throws an error known as a syntax error.

24.What is Exception?
Even if a statement or expression is syntactically correct, it may cause an error when
an attempt is made to execute it (at run time).
Errors detected during execution are called exceptions

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

25.What is Exception Handling in Python?


Exception handling allows you to separate error-handling code from normal code.
An exception is a Python object which represents an error.
As with code comments, exceptions helps you to remind yourself of what the
program expects.
It clarifies the code and enhances readability

26.How exception handled in python?


The try and except block in Python is used to catch and handle exceptions.
Python executes code following the try statement as a “normal” part of the program.
The code that follows the except statement is the program's response to any
exceptions in the preceding try clause.

27.What are the keywords available for exception handling?


• try
• except
• else
• finally

28.What is built in exception?


Exceptions that are already available in Python libraries are referred to as built-in
exception.
These exceptions are able to define the error situation so that we can understand the
reason of getting this error

29.List out some built in exception in python.


ArithmeticError : Raised when an error occurs in numeric calculations
ImportError : Raised when an imported module does not exist
IndexError: Raised when an index of a sequence does not exist
NameError: Raised when a variable does not exist
TypeError : Raised when two different types are combined

30.Why finally block is used in exception handling?


This can be useful to close objects and clean up resources.
Usually close the database, network connections and de-allocate the memory.

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

Finally block statements are executed whether an exception is handled or not.

31.What are the conditional statements in python?


• if
• if ….else
• if - elif

32.Write the syntax of if statement.


if condition:
# Statements to execute if
# condition is true

33.Write the syntax of if else statement.


if condition:
# Statements to execute if
# condition is true
else:
# Statements to execute if
# condition is false

34.Write the syntax of if elif statement.


if condition1:
# Statements1
elif condition2:
# Statements2
else:
# Statements3

35.What is nested if statement?


If statement inside another if statement is called nested if.

if condition1:
# Statements1
if condition2:
# Statements2
else:
# Statements3
else:
# Statements4

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

36.What are the looping statements in python


• for loop
• while loop

37.Write the syntax of for loop?

for variable in sequence:


# Statements

38.What is range function?


The range() function returns a sequence of numbers, starting from 0 by default, and
increments by 1 (by default), and stops before a specified number.

39.Write the syntax of while loop?

while condition:
# Statements

40.What is sequence in python


Sequences are containers with items stored in a deterministic ordering.
Each sequence data type comes with its unique capabilities.
Collection of items stored in a single name is called sequence.

41.What is List?
A list is a data structure in Python that is a mutable, or changeable, ordered sequence
of elements.
Each element or value that is inside of a list is called an item.
It allows duplicate values and created by square brackets.

42.What is Tuple?
A tuple is a data structure in Python that is a immutable, ordered sequence of
elements.
Each element or value that is inside of a tuple is called an item.
It allows duplicate values and created by round brackets.

S.PRABU, Assistant Professor, SRMIST-KTR


21CSS101J PROGRAMMING FOR PROBLEM SOLVING LAB

43.What is Set?
A set is a data structure in Python that is a mutable, or changeable, not a ordered
sequence of elements.
Each element or value that is inside of a set is called an item.
It does not allows duplicate values and created by curly braces.

44.Compare List, Tuple and Set

List [ ] Mutable Ordered Allow Duplicate values

Tuple ( ) Immutable Ordered Allow Duplicate values

Set { } Mutable Unordered No Duplicate values

S.PRABU, Assistant Professor, SRMIST-KTR

You might also like