0% found this document useful (0 votes)
54 views7 pages

Python Question Bank

The document provides questions and answers related to Python programming concepts. It covers topics like algorithms, functions, conditionals, loops, data structures like lists, tuples, dictionaries, sets, and more. Example programs and explanations are provided for key concepts like functions, conditionals, loops, operators, scopes, data structures and their methods. Testing frameworks like Pytest are also discussed along with examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views7 pages

Python Question Bank

The document provides questions and answers related to Python programming concepts. It covers topics like algorithms, functions, conditionals, loops, data structures like lists, tuples, dictionaries, sets, and more. Example programs and explanations are provided for key concepts like functions, conditionals, loops, operators, scopes, data structures and their methods. Testing frameworks like Pytest are also discussed along with examples.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

22CS303 PROGRAMMING FOR SOLVING PROBLEM IN PYTHON

QUESTION BANK

1.Define algorithm.

It is defined as a sequence of instructions that describe a method for solving a


problem. In other words it is a step by step procedure for solving a problem.

Properties of Algorithms

• Should be written in simple English

• Each and every instruction should be precise and unambiguous.

• Instructions in an algorithm should not be repeated infinitely.

• Algorithm should conclude after a finite number of steps.

• Should have an end point

• Derived results should be obtained only after the algorithm terminates.

2. Distinguish between Compiler and Interpreter

COMPILER INTERPRETER
The compiler saves the The Interpreter does
Machine Language in form not save the Machine
of Machine Code on disks. Language.
Compiled codes run faster Interpreted codes run
than Interpreter. slower than Compiler.
Linking-Loading Model is The Interpretation
the basic working model of Model is the basic
the Compiler. working model of the
Interpreter.

3. Define debugging and types of error in python.

Errors occurring in programming are called as bugs. The process of tracking these
bugs is called as debugging.

 There are three types of errors that can occur while coding: Syntax Error,
Runtime Error and Semantic Error.
4. What are the features and applications of Python?

Features of python.

1.Free and open source.


2.Easy to code
3.Easy to Read
4.Object oriented language.
5.GUI programming support.

Applications of python:
Python is commonly used for developing websites and software, task
automation, data analysis, and data visualization.

5.Define list:

Python Lists are similar to arrays in C. However, the list can contain data of

different types.

* The items stored in the list are separated with a comma (,) and enclosed

within square brackets [].


*We can use slice [:] operators to access the data of the list.

6.Define tuples.

*A tuple is a collection which is ordered and unchangeable.


*Tuples are written withround brackets.
*Tuple items are indexed, the first item has index [0], the second item has
index [1] etc.

7. List the built-in tuple functions.

Len()
Max()
Min()
Tuple()

8.Define dictionary.
*Dictionaries are used to store data values in key:value pairs.

*A dictionary is a collection which is ordered*, changeable and do not allow


duplicates.

Dictionaries are written with curly brackets, and have keys and values:

thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)

9.Define flowchart.

Flowchart is a graphical representation of an algorithm. Programmers often


use it as a program-planning tool to solve a problem. It makes use of symbols
which are connected among them to indicate the flow of information and
processing.

10.Define varaiable and its types.

A variable can have a short name (like x and y) or a more descriptive name
(age, carname, total_volume). Rules for Python variables:

 A variable name must start with a letter or the underscore character


 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
 Variable names are case-sensitive (age, Age and AGE are three different
variables)
 A variable name cannot be any of the Python keywords.

TYPES:

Local variable.

Global variable.

11.Define function as object in python.


One of the most powerful features of Python is that everything is an object, including functions.

Functions in Python are first-class objects.This broadly means, that functions in Python:

This broadly means, that functions in Python:

 have types

 can be sent as arguments to another function

 can be used in expression

 can become part of various data structures like dictionaries

12. Define function with example program.

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:

ExampleGet your own Python Server


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

13. Analyze the expected output of following programs:

i) x = range (3, 20, 2)

for n in x:

print(n)

output:(3,5,7,9,11,13,15,17,19)

14.Write a Python program to print a specified list after removing

the 0th, 2nd and 4th elements. Sample List: [“Red”, “Green”,
“Black”, “Pink”, “Yellow”]

Output:[“Green”,”Pink”]

15. What is type casting? List its types.

Type Casting is the method to convert the Python variable datatype into a certain data type in
order to perform the required operation by users. In this article, we will see the various
techniques for typecasting. There can be two types of Type Casting in Python:
 Python Implicit Type Conversion
 Python Explicit Type Conversion

16. Analyze the expected output of following dictionary programs:


i) car = {“brand”:”ford”,”model”:”mustang”,”year”:1964}
car.popitem(“model”)
print(car)

OUTPUT: {{“brand”:”ford”,”year”:1964}

17.Illustrate PYTEST:

Pytest is a python based testing framework, which is used to write and execute test codes. In the
present days of REST services, pytest is mainly used for API testing even though we can use
pytest to write simple to complex tests, i.e., we can write codes to test API, database, UI, etc.

Advantages of Pytest

The advantages of Pytest are as follows −

 Pytest can run multiple tests in parallel, which reduces the execution time of the test
suite.
 Pytest allows us to skip a subset of the tests during execution.
 Pytest allows us to run a subset of the entire test suite.
 Pytest is free and open source.

QUESTIONS (13MARKS&15MARKS)

1. Explain about conditional statements in python with

its syntax and suitable example program. (if, elif and else)
2.Write a python program to calculate grade of students

using nested elif statement.


Calculate Grade of Student based on Marks

obtained in 5 Subjects.

Based on Marks obtained in n number of

Subjects.

3. Explain in detail about building blocks of algorithms with example.

4.Explain in detail about python operators.

5.Classify the problem-solving techniques for sum of two numbers.

6.Implement a python program to check weather given number is positive or negative or zero
and draw the flowchart for the program.

7.Design a python program to print the star pattern in right angle triangle using while loop.

8. Discuss the different types of errors in python and give your suggestion to achieve debugging
in python.

9.Consider the list, list1 = [9,8,7,6,5,4,3]. Write the Python

program which performs the following operation without using built-in methods.

1) Insert element 10 at beginning of the list.

2) Insert element 2 at end of the list.

3) Delete the element at index position 5.

10. Discuss in detail about local scope and global scope with example program.

11.To create a list and perform the following operation

1.Accessing the element

2.slicing the element

3.append ()

4.insert ()

5.count () ,6.pop () ,7.clear ()

I2.Discuss operations in tuple.

13.Explain about Method on Set with suitable example..


14.Elaborate the different types of arguments in python function with example program

15. Write a program to find Sum of N natural numbers using with and without while loop & for
loop and draw the flowchart.

16. Elaborate function as object in python.

17.Explain the following:

a) argument behavior

b) Parameterized PYTEST

18.Write an algorithm, pseudocode and draw the flowchart for the following program:

To find whether a number is prime or not.

19. Explain about operations on Dictionary with suitable example.

20.Explain about string slicing and Range () function with examples.

You might also like