Ca - Q and A

You might also like

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 4

CA- Q and A

1.What are the types of errors we face while doing program?


Ans- There are mainly three types of errors:
i)Syntax error
ii)Logic error
iii)Runtime error
i)Syntax error occurs when the given code by the user doesn’t match with the programming
language.

ii)Logic error happens as the programming happens. It runs the programming but doesn’t run as it is
expected.

iii)Run time error happens during the running of the program

2)Difference between Interpreter and a compiler?

Ans-
Interpreter Compiler
Scans the entire program and translates it as a
Translates program one statement at a time.
whole into machine code.
Interpreters usually take less amount of time to Compilers usually take a large amount of time to
analyse the source code. However, the overall analyse the source code. However, the overall
execution time is comparatively slower than execution time is comparatively faster than
compilers. interpreters.
No Object Code is generated, hence are memory Generates Object Code which further requires
efficient. linking, hence requires more memory.
Programming languages like JavaScript, Python, Programming languages like C, C++, Java use
Ruby use interpreters. compilers.

3) Describe computer hardware architecture on your own words.

Ans-
A hardware architecture is primarily concerned with the internal electrical (and, more
rarely, the mechanical) interfaces among the system's components or subsystems, and the
interface between the system and its external environment, especially the devices
operated by or the electronic displays viewed by a user.

4)Explain try and except in Python?

Ans-
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.

5)Write a note on Short-circuit evaluation in logical expression in python?


Ans-
By short-circuiting, we mean the stoppage of execution of boolean operation if the truth
value of expression has been determined already. The evaluation of expression takes
place from left to right. In python, short-circuiting is supported by various boolean
operators and functions.
6) What is built in function? Give your example.

Ans-
Built-in functions are pre-defined in the programming language’s library, for the
programming to directly call the functions wherever required in the program for
achieving certain functional operations. Example-Boolean, Float, Integer.

7)What are the advantages of using function in programming?

Ans-
Reducing duplication of code.
•Decomposing complex problems into simpler pieces.
•Improving clarity of the code.
•Reuse of code.
•Information hiding.
8)What are break and continue statement used for in python?
Ans-
In Python, break and continue statements can alter the flow of a normal loop. Loops iterate
over a block of code until the test expression is false, but sometimes we wish to terminate
the current iteration or even the whole loop without checking test expression.
The  break statement terminates the loop containing it. Control of the program flows to
the statement immediately after the body of the loop.
If the  break statement is inside a nested loop (loop inside another loop),
the  break statement will terminate the innermost loop.

The  continue statement is used to skip the rest of the code inside a loop for the current
iteration only. Loop does not terminate but continues on with the next iteration.

9)Describe at least six string methods.


Ans-
find() Returns the lowest index of the substring if it is found

index() Returns the position of the first occurrence of a substring in a string

replace() Replaces all occurrences of a substring with another substring

upper() Converts all lowercase characters in a string into uppercase

count() Returns the number of occurrences of a substring in the string.


capitalize() Converts the first character of the string to a capital (uppercase) letter
10)What are lists and describe the characteristics of list?
Ans-In short, a list is a collection of arbitrary objects, somewhat akin to an array in
many other programming languages but more flexible. Lists are defined in Python by
enclosing a comma-separated sequence of objects in square brackets ([]).
The important characteristics of Python lists are as follows:
•Lists are ordered.

•Lists can contain any arbitrary objects.

•List elements can be accessed by index.

•Lists can be nested to arbitrary depth.

•Lists are mutable.

•Lists are dynamic.

11)Mention the five methods in list data structure.


append(): Used for appending and adding elements to List. It is used to add elements to
the last position of List.
insert(): Inserts an elements at specified position
extend(): Adds contents to List2 to the end of List1.
sum(): Calculates sum of all the elements of List.
count():Calculates total occurrence of given element of List.

More Questions to Search:


1. WAP to convert temperature in centigrade to Fahrenheit.
2. WAP to convert temperature in centigrade to Fahrenheit.
3. WAP to convert ‘n’ minutes into hours and minutes format where n is given by the
user. i.e. 200 minutes = 3 hrs. 20 minutes.
4. WAP to display the sum of first ‘n’ numbers where n is given by the user.
5. WAP to generate the first ‘n’ terms in a Fibonacci series where the value of n is
given by the user.
6. WAP to ask the user to think of a number below 1 lakh. The program should guess
the number and keep track of the number of attempts made until the number given
by the program is the same as the number which the user has in mind.
7. Write a Python function named zero Check that is given three integers, and returns true if
any of the integers is 0, otherwise it returns false.
8. Write a Python function named ordered3 that is passed three integers, and returns true if
the three integers are in order from smallest to largest, otherwise it returns false.
9. Generate a Python list of all the even numbers between 4 to 50.

You might also like