5units 2marks and Answers
5units 2marks and Answers
Page 1 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit I - 2 Marks Q & A
Finding greatest of two numbers includes , different logic for comparing two numbers as defining the variables
as a & b , logics include a>b or a<b or a%b == a or a%b ==b or any logic can be defined and finally the
program is implemented.
9. Define a flowchart.
Flow chart is defined as graphical representation of the logic for problem solving.
The purpose of flowchart is making the logic of the program clear in a visual representation.
A flowchart is a type of diagram that represents a workflow or process.
The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows.
This diagrammatic representation illustrates a solution model to a given problem.
Page 2 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit I - 2 Marks Q & A
Page 3 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit I - 2 Marks Q & A
19. Differentiate high level, low level and assembly level languages
Low level/ Machine level language Assembly level language High level language
Programs are written only in 0s and Programs are wirtten in mnuemonics Programs are written using English
1s ie. binary will be understood by like ADD A,B words and symbols.
the computer.
There is no conversion required. The Assembler converts the The compiler and the interpreter
assembly level language to the does the conversion of the high level
machine language. languages to the machine language.
20. What are the simple strategies for developing an algorithm?
Simple strategies for developing an algorithm include Iteration and Recursion
Iteration: Sequence of statements executed repeatedly until a specified condition is satisfied is iteration.
Recursion: A function that calls itself again and again until a specified condition is satisfied is called recursion.
PART B
Page 4 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit II - 2 Marks Q
GE3151 PROBLEM SOLVING AND PYTHON PROGRAMMING
UNIT II DATA, EXPRESSIONS, STATEMENTS
PART – A (2 MARKS)
2. What is a tuple? How literals of type tuple are written? Give example.(D/J-18).
A tuple is created by surrounding objects with ()'s and separating the items with commas (,). An empty tuple is
empty ()'s. An interesting question is how Python tells an expression from a 1-tuple. A 1-element tuple has a
single comma: (1,). An expression lacks the comma: (1). A pleasant consequence of this is that an extra comma
at the end of every tuple is legal; for example, (9, 10, 56, ).
Examples:
xy= (2, 3)
personal= ('John',14,5*12+6)
singleton= ("hello",)
The elements of a tuple do not have to be the same type. A tuple can be a mixture of any Python data types,
including other tuples
3. Outline the logic to swap the contents of two identifiers without using third variable.(A/M-19)
Logic:
a=int(input(“Enter the value of a”))
b=int (input(“Enter the value of b”))
a=a+b
b=a-b
a=a-b
print(a,b)
4. State about Logical operators available in python language with example. (A/M -19)
In Python, the primary logical operators are AND, OR, and NOT. A boolean expression or valid expression
evaluates to one of two states True or False. Python provides the boolean type that can be either set to False or
True. Many functions and operations return boolean objects.
Page 1 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit II - 2 Marks Q
10. Define variables in python.
In Python, variables are a storage placeholder for texts and numbers. It must have a name so that you are able to
find it again. The variable is always assigned with the equal sign, followed by the value of the variable.
16. Point out the difference between recursive and iterative technique.
• Recursive approach: In recursive approach the function calls itself until the condition is met. And it is slower
than iteration, which means it uses more memory than iteration. Recursion is like a selection structure, and
which makes code smaller and clean. And a function partially defined by itself. Here tracing the code will be
more difficult in the case large programs.
• Iterative approach: Iterative approach is a repetition process until the condition fails, here loops are used
such as for, while etc. Here code may be longer but it is faster than recursive. And it consumes less memory
compared to recursive approach. If the loop condition is always true in such cases it will be an infinite loop
Page 2 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit II - 2 Marks Q
19. What is meant by interpreter?
An interpreter is a computer program that executes instructions written in a programming language. It can either
execute the source code directly or translate the source code in a first step into a more efficient representation
and executes this code.
24. Define a variable and write down the rules for naming a variable.
A name that refers to a value is a variable. Variable names can be arbitrarily long. They can contain both letters
and numbers, but they have to begin with a letter. It is legal to use uppercase letters, but it is good to begin
variable names with a lowercase letter.
1. Sketch the structures of interpreter and compiler. Detail the difference between them. Explain how python
works in interactive mode and script mode with examples.( D/J -19)
2. Summarize the precedence of mathematical operators in python.( D/J -19)
3. Explain the syntax and structure of user defined functions in Python with examples. Also discuss about
parameter passing in functions.( D/J -19)
4. Write a python function to swap the values of two variables.( D/J -19)
5. Describe about the concept of precedence and associativity of operators with example.(A/M-19)
6. Mention the list of keywords available in Python. Compare it with variable name.(A/M-19)
7. What are statements? How are they constructed from variable and expressions in Python? (A/M-19)
8. What is a numeric literal? Give examples.(D/J-18)
9. Appraise the arithmetic operators in Python with an example. (D/J-18)
10. Outline the operator precedence of arithmetic operators in Python. (D/J-18)
11. Write a Python program to exchange the value of two variables. (D/J-18)
12. Write a Python using function to find the sum of first “n” even numbers and print the result. (D/J-18).
13. Explain various types of operators used in Python.
14. Explain Values & types supported in Python.
15. What are the different function prototypes? Explain it with suitable example.
16. What are the different types of arguments available in python.
17. Explain in detail the different ways of importing a module in python.
18. Write a python program to circulate values of n variables.
Page 4 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit III - 2 Marks Q
GE3151 - PROBLEM SOLVING AND PYTHON PROGRAMMING
UNIT III - CONTROL FLOW, FUNCTIONS
PART- A (2 Marks)
1. What a python program to accept two inputs, find the greatest and print the result ?
Num1= int(input(“enter the value of num1”))
Num2= int(input(“enter the value of num2”))
if(Num1>Num2):
print(“Num1 is greatest”)
else:
print(“Num2 is greatest”)
4. Comment with an example on the use of local and global variables with the same identifier name.
Local: The value which is declared inside the function
Global: The value which is declared outside the function
a=5
def test():
a=10
print(a)
print(a)
Page 1 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit III - 2 Marks Q
x <= y # x is less than or equal to y
elif is an abbreviation of “else if” Again, exactly one branch will be executed. There is no limit on the number of
elif statements. If there is an else clause, it has to be at the end, but there doesn’t have to be one.
Page 2 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit III - 2 Marks Q
Example:
x=4
for i in range(0, x):
print(i)
Composition:
Calling one function from another is called composition.
Example:
def circle_area(xc, yc, xp, yp):
radius = distance(xc, yc, xp, yp)
result = area(radius)
return result
Page 4 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit IV - 2 Marks Q
GE3151 - PROBLEM SOLVING AND PYTHON PROGRAMMING
UNIT IV - COMPOUND DATA: LISTS, TUPLES, DICTIONARIES
PART- A (2 Marks)
1. What is a list?
A list is an ordered set of values, where each value is identified by an index.
Values in the list are called elements / items. It can be written as a list of comma-separated items (values)
between square brackets [ ].
Items in the lists can be of different data types and List is a mutable type.
>>>[1, 2, 3] * 3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
3. Let list = [’a’, ’b’, ’c’, ’d’, ’e’, ’f’]. Find a) list[1:3] b)list[:4] c) list[3:] .
>>> list = [’a’, ’b’, ’c’, ’d’, ’e’, ’f’]
>>> list[1:3]
[’b’, ’c’]
>>> list[:4]
[’a’, ’b’, ’c’, ’d’]
>>> list[3:]
[’d’, ’e’, ’f’]
Page 1 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit IV - 2 Marks Q
2. list()method
3. copy()method
Example:
>>>a=[1,2,3,4,5]
>>>b=a[:]
>>>print(b)
[1,2,3,4,5]
>>>a is b
False
Page 2 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit IV - 2 Marks Q
a=eval(input("enter a value:"))
b=eval(input("enterb value:"))
r,q = div(a,b)
print("reminder:",r)
print("quotient:",q)
18. How to create a list in python? Illustrate the use of negative indexing of list with example.
List is an ordered sequence of items. Values in the list are called elements / items. It can be written as a list of
comma-separated items (values) between square brackets [ ]. Items in the lists can be of different data types.
Example:
>>> a = [1,2,3]
>>> print(a)
[1,2,3]
Negative Indexing
Python supports negative indexing for a sequence types like list. The last item on the list takes the -1 index and
second to the last item has the -2 index and so on.
>>> a = [1,2,3]
>>> print(a[-1])
3
>>> print(a[-2])
2
Page 3 of
Saranathan College of Engineering, Tiruchirappalli -
GE3151 - Problem Solving and Python Programming - Unit IV - 2 Marks Q
Lists are mutable (can be changed). Mutability is the ability for certain types of data to be changed without
entirely recreating it.
An item can be changed in a list by accessing it directly as part of the assignment statement.
Using the indexing operator (square brackets [ ]) on the left side of an assignment, one of the list items can be
updated.
Page 4 of
Saranathan College of Engineering, Tiruchirappalli -