Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python programming question bank, Assignments of Programming Methodologies

It provides you with the various concepts of Python programming language

Typology: Assignments

2021/2022

Available from 11/18/2023

jatin-singh-10
jatin-singh-10 🇮🇳

1 document

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Define
Algorithm
UNIT I
PART-A
PROBLEM SOLVING AND PYTHON PROGRAMMING
Algorithm : It is a sequence of instructions designed in such a way that if the
instructions are executed in the specified sequence, the desired results will be obtained.
The instructions in an algorithm should not be repeated infinitely. The algorithm should
be written in sequence.
2.What are the properties of algorithm?
It is written in simple English.
Each step of an algorithm is unique and should be self
explanatory. An algorithm must have at least one input.
An algorithm must have at least one
output. An algorithm has finite number of steps.
3.What are the building block of algorithm?
The three building block of algorithm are :
Sequence
Selection
Iteration
4.What is meant by selection, iteration and sequence
controlstructures? Sequence:
A sequence is one of the basic logic structures in computer programming.
In a sequence structure, an action, or event, leads to the next ordered action in a
predetermined order.
Selection:
A selection (also called a decision) is also one of the basic logic structures
in computer programming. In a selection structure, a question is asked, and
depending on the answer, the program takes one of two courses of action, after
which the program moves on to the next event.
Selection: A selection (also called a decision) is also one of the basic logic
structures in computer programming. In a selection structure, a question is asked,
and depending on the answer, the program takes one of two courses of action,
after which the program moves on to the next event.
5.Define Flowchart
It is a pictorial representation of an algorithm. The flowchart uses different shape
symbols to denote the different appropriate instructions and these instructions can be
written within the boxes using clear statements.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Python programming question bank and more Assignments Programming Methodologies in PDF only on Docsity!

1. Define Algorithm

UNIT I

PART-A

PROBLEM SOLVING AND PYTHON PROGRAMMING

Algorithm : It is a sequence of instructions designed in such a way that if the instructions are executed in the specified sequence, the desired results will be obtained. The instructions in an algorithm should not be repeated infinitely. The algorithm should be written in sequence. 2.What are the properties of algorithm?  It is written in simple English.  Each step of an algorithm is unique and should be self  explanatory. An algorithm must have at least one input.  An algorithm must have at least one  output. An algorithm has finite number of steps. 3.What are the building block of algorithm? The three building block of algorithm are : Sequence Selection Iteration 4.What is meant by selection, iteration and sequence controlstructures? Sequence: A sequence is one of the basic logic structures in computer programming. In a sequence structure, an action, or event, leads to the next ordered action in a predetermined order. Selection: A selection (also called a decision) is also one of the basic logic structures in computer programming. In a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event. Selection: A selection (also called a decision) is also one of the basic logic structures in computer programming. In a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event. 5.Define Flowchart It is a pictorial representation of an algorithm. The flowchart uses different shape symbols to denote the different appropriate instructions and these instructions can be written within the boxes using clear statements.

6. Write the Characteristics of Pseudo code. Named variables represent data and identifiers denote higher level functions. Composed of a sequence of statements or steps.  Statements are often numbered sequentially.  Operational (Imperative) statements include assignment, input, and outpu Control structures provide iterative and conditional execution. Indentations used for grouping b 8. What is need for flowchart symbol? The need for flowchart symbols because each symbols of different shapes denotes different types of instructions. The program logic through flowcharts is made easier through the use of symbol that has standardized planning. **9. Write some rules for drawing a flowchart.

  1. What are the advantages of using a flowchart**  Communication  Effective  Proper  Documentation  Efficient Coding  Proper  Debugging  Efficient Program Maintenance 11. Write any two disadvantages of flowchart?  It is not visual  We do not get a picture of the design. 12. What is Pseudo code? ―Pseudo‖ means imitation of false and ―code‖ refers to the instruction written in a programming language. Pseudo code is programming analysis tool that is used for planning program logic. 13. Write the Characteristics of Pseudocode.  Named variables represent data and identifiers denote higher level  functions.  Composed of a sequence of statements or steps.  Statements are often numbered sequentially.  Operational (Imperative) statements include assignment, input, and  output.  Control structures provide iterative and conditional execution.

PART-B

  1. Define algorithm. Explain in detail about the building blocks of algorithm.
  2. What is flowchart. Explain the Basic design structures in Flowchart
  3. What is pseudo code? Explain its guidelines and benefits.
  4. Explain the design structures in pseudo code.
  5. Explain the steps involved in program development cycle.
  6. Write the algorithm, pseudocode and draw the flowchart for the following: a. Find minimum in a list. b. Insert a card in a list of sorted cards. c. Guess an integer number in a range. d. Towers of Hanoi.
  7. Write the algorithm, pseudocode and draw the flowchart for the following: a) To find the sum of square root of any three numbers. b) To find the sum of first 100 integers. c) To find the sum of all odd numbers till 100. d) To find the sum of any five integers. e) To find the factorial of number n. f) To find the first n numbers in a Fibonacci series. g) To find the sum of digits of a number. h) To find whether a number is prime or not. i) To convert temperature from Fahrenheit to Celsius j) To solve the quadratic equation. k) To find sum first 100 natural numbers. l) To find factorial of a number.

UNIT-II

1. Define python

PART A

DATA, EXPRESSIONS AND STATEMENTS

Python is an object-oriented, high level language, interpreted, dynamic and multipurpose programming language.

2. Give the features of python.  Easy to Use:  Expressive Language  Interpreted Language  Cross-platform language  Free and Open Source  Object-Oriented language  Extensible 3. What is python interpreter? The engine that translates and runs Python is called the Python Interpreter: There are two ways to use it: immediate mode and script mode. The >>> is called the Python prompt. The interpreter uses the prompt to indicate that it is ready for instructions. 4. What is the difference between intermediate mode and script mode?  In immediate mode, you type Python expressions into the Python Interpreter window, and the interpreter immediately shows the result.  Alternatively, you can write a program in a file and use the interpreter to execute the contents of the file. Such a file is called a script. Scripts have the advantage that they can be saved to disk, printed, and so on. 4. What is meant by value in python? A value is one of the fundamental things—like a letter or a number—that a program manipulates. 5. List the standard data types in python. Python has five standard data Types: Numbers Strings List, Tuples Dictionary

9. What is tuple? What is the difference between list and tuple?  A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas.  The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists. Eg: tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) 10. Give the features of python dictionaries Python's dictionaries are kind of hash table type. They work like associative arrays and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]). For example − dict = {} dict['one'] = "This is one" 11. What is a variable? One of the most powerful features of a programming language is the ability to manipulate variables. A variable is a name that refers to a value. The assignment statement gives a value to a variable. Eg:

n = 17 pi = 3. 12. What are the rules for naming a variable? Variable names can be arbitrarily long. They can contain both letters and digits, but they have to begin with a letter or an underscore. Although it is legal to use uppercase letters, by convention we don‘t. If you do, remember that case matters. Bruce and bruce are different variables. The underscore character ( _) can appear in a name. Eg: my_name 13. What are keywords? Keywords are the reserved words in Python. We cannot use a keyword as variable name, function name or any other identifier. They are used to define the syntax and structure of the Python language In Python, keywords are case sensitive. There are 33 keywords in Python. Eg: False, class, finally, return

14. What are the rules for writing an identifier?  Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore (). Names like myClass, var and print_this_to_screen, all are valid example.  An identifier cannot start with a digit. 1variable is invalid, but variable is perfectly fine. Keywords cannot be used as identifiers.  We cannot use special symbols like !, @, #, $, % etc. in our  identifier. Identifier can be of any length. 15. what are expressions? An expression is a combination of values, variables, operators, and calls to functions. If you type an expression at the Python prompt, the interpreter evaluates it and displays the result:

1 + 1= 16. What is a statement? A statement is an instruction that the Python interpreter can execute. When you type a statement on the command line, Python executes it. Statements don‘t produce any result. For example, a = 1 is an assignment statement. if statement, for statement, while statement etc. are other kinds of statements. 17. What is multiline statement? In Python, end of a statement is marked by a newline character. But we can make a statement extend over multiple lines with the line continuation character (). For example: a = 1 + 2 + 3 + \

 4 + 5 + 6 + \ 7 + 8 + 9 

18. What is docstring? Doc string is short for documentation string. It is a string that occurs as the first statement in a module, function, class, or method definition. It is used to explain in brief, what a function does. 19. What is a function? Mention the type of function and use. A Function can be called as a section of a program that is written once and can be executed whenever required in the program, thus making code reusability. There are two types of Functions. a) Built-in Functions: Functions that are predefined. We have used many predefined functions in Python. b) User- Defined: Functions that are created according to the requirements. 20. Mention the types of arguments in python 1.python default arguments. 2.python keyword argument

32. Give the characteristics of membership operator? in and not in are the membership operators in Python. They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary).In a dictionary we can only test for presence of key, not the value. Operator Meaning Example in True if value/variable is found in the sequence 5 in x not in True if value/variable is not found in the sequence 5 not in x PART B

  1. Explain the data types in python
  2. Ilustrate interpreter and interactive mode in python with example. 3.Explain function and module with suitable example
  3. Write short notes on types of operators in python with appropriate example 5.Explain briefly constant, variables, expression, keywords and statements available in python 6.Write the following python programs. a. Exchange the value of two v b.Circulate the value of n variables c. Test whether a given year is leap year or not d. to find the sum of n natural numbers e. To find whether a given number is Armstrong number or not f. To print Fibonacci series g. To find factorial of a given number h. To convert Celsius to Fahrenheit

UNIT III PART A

CONTROL FLOW AND FUNCTIONS

1. What is Boolean value? A Boolean value is either true or false. In Python, the two Boolean values are True and False (the capitalization must be exactly asshown), and the Python type is bool.

type( True ) 2.What is Boolean Expression?  A Boolean expression is an expression that evaluates to produce a result which is a Booleanvalue. For example, the operator == tests if two values are equal. It produces (or yields) aBoolean value:  >>> 5 == (3 + 2) # Is five equal 5 to the result of 3 + 2?  True 3.What is meant by conditional If? The if statement in python is used to test a condition. If condition is true, statement of if block is executed otherwise it is skipped. Syntax of python if statement: if(condition): statements 4.What is chained conditional statement? To check for multiple conditions elif Statement is used.This statement is like executing a if statement inside a else statement. Syntax: If statement: statements elif statement: statements else: statements 5.Write the syntax and usage of for loop For Loop is used to iterate a variable over a sequence(i.e., list or string) in the order that they appear. Syntax: for in : 6.Write the syntax and usage of while loop While Loop is used to execute number of statements or body till the condition passed in while is true. Once the condition is false, the control will come out of the loop.

‘V‘ in ‗VRB‘ True ‘S‘ in ‗VRB‘ False The not in operator returns the logical opposite results of in operator. ‘x‘ not in ‗VRB‘ True 13.What is the use of str.upper() and str.lower() functions in string? The functions str.upper() and str.lower() will return a string with all the letters of original string converted to upper or lower case letters. ss=‘VRB Publishers‘ print(ss. upper()) VRB PUBLISHE RS print(ss .lower()) Vrb publishers 14.Explain string comparison with an example. The comparison operator works on string to check if two strings are equal. word=‘VRB Publishers‘ if word==‘VRB Publishers‘ Print(‗Both are Equal‘) Both are Equal 15.How to split strings and what function is used to perform that operation? The str.split() method is used to split strings up. book=‘Problem Solving and Python Programming‘ print(book.split()) [‗Problem‘, ‗Solving‘, ‗and‘, ‗Python‘, ‗Programing‘] PART B

  1. Explain the function arguments in python
  2. Explain call by value and call by reference in python 3.Briefly explain about function prototypes
  3. Answer the following questions. What is String? How do u create a string in Python? (4 marks) How to perform a user input in Python? Explain with example. (4 marks)

Write a program to check whether entered string is palindrome or not. (8 marks) 5.Answer the following questions. What is the output produced by this program given below? (8 marks) words = ‗Hello World‘ print words.title() print words.replace(―World‖,‘Osw al‘) print words.upper() print words* Assuming num=125, determine the value of each of the following Python expressions. (8 marks) (i) num/125 (ii)num %100 (iii)(num== 1)&(2<3) (iv)not((num<45.9)&(6*2<=13))

6. How lists are updated in Python? The append() method is used to add elements to a list. Syntax: list.append(obj) List=[123,‘VR B‘] List.append(2017) Print(― Updat ed List:‖, List) Output: Updated List: [123,‘VRB‘,2017] 7. Write a few methods that are used in Python Lists. a) append()- add an element to end of list b) insert()- insert an item at the defined index c) remove()- removes an item from the list d) clear()- removes all items from the list e) reverse()- reverse the order of items in the list 8. What are the advantages of Tuple over List?  Tuple is used for heterogeneous data types and list is used for homogeneous data types.  Since tuple are immutable, iterating through tuple is faster than with list.  Tuples that contain immutable elements can be used as key for dictionary.  Implementing data that doesn‘t change as a tuple remains write-protected. 9. What is indexing and negative indexing in Tuple? The index operator is used to access an item in a tuple where index starts from 0. Python also allows negative indexing where the index of -1 refers to the last item, -2 to the second last item and so on.

my_tuple=(‗p‘,‘y‘,‘t‘,‘h‘,‘o‘,‘n‘) print(my_tuple[5] ) n print(m y_tuple[- 6]) p 10. What is the output of print tuple[1:3] if tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )? In the given command, tuple[1:3] is accessing the items in tuple using indexing. It will print elements starting from 2nd till 3rd. Output will be (786, 2.23). 11. What are the methods that are used in Python Tuple? Methods that add items or remove items are not available with tuple. Only the

following two methods are available:

If someone buys all of the pears, we can remove the entry from the dictionary:

del inventory[‘pears‘] print inventory {‘oranges‘: 525, ‘apples‘: 430, ‘bananas‘: 312}

18. What is meant by invocation? Where is it used and how? csenotescorner.blogs A method is similar to a function—it takes arguments and returns a value— but the pot.com syntax is different. For example, the keys method takes a dictionary and returns a list of the keys that appear, but instead of the function syntax keys(eng2sp), we use the method syntax eng2sp.keys().

eng2sp.keys() [‘one‘,‘three‘,‘two‘] This form of dot notation specifies the name of the function, keys, and the name of the object to apply the function to, eng2sp. The parentheses indicate that this method has no parameters. A method call is called an invocation; in this case, we would say that we are invoking keys on the object eng2sp. 19. Explain values and items method used in dictionary with example. The values method is similar; it returns a list of the values in the dictionary:

eng2sp.v alues() [‘uno‘,‘tres‘,‘dos‘] The items method returns both, in the form of a list of tuples—one for each key-value pair:

eng2sp.items() [(‘one‘,‘uno‘), (‘three‘, ‘tres‘), (‘two‘, ‘dos‘)] The syntax provides useful type information. The square brackets indicate that this is a list. The parentheses indicate that the elements of the list are tuples. 20. What is the difference between modify and copy operations performed in

**dictionary?** If you want to modify a dictionary and keep a copy of the original, use 

the copy method. For example, opposites is a dictionary that contains pairs of opposites:

opposites = {‘up‘: ‘down‘, ‘right‘: ‘wrong‘, ‘true‘: ‘false‘} alias = opposites copy = opposites.copy() alias and opposites refer to the same object; copy refers to a fresh copy of the same dictionary. If we modify alias, opposites is also changed: alias[‘right‘] = ‘left‘ opposites[‘ right‘] ‘left‘ If we modify copy, opposites is unchanged: copy[‘right‘] = ‘privilege’

PART_B

  1. Answer the following questions. Write short note on Functional Programming Approach. (4 marks) What is the difference between Lists and Tuples? Give an example for their usage. (4 marks) Explain the purpose of loop structure in a programming language. Describe the syntax and semantics of any two loop structures provided by Python. ( marks)
  2. Answer the following questions. Explain the features of a dictionary. (5 marks) What are the three types of import statement in Python? Explain. (6 marks) Write a short note on assert function. (5 marks)
  3. Answer the following questions. What is the difference between lists, tuples and dictionaries? Give an example for their usage. (6 marks) What type of conditional structures are present in a programming language? How many of them are supported in Python? Explain each with example. (10 marks)
  4. What are the basic list operations that can be performed in Python? Explain each operation with its syntax and example. ( marks)
  5. What is Dictionary? Explain Python dictionaries in detail discussing its operations and methods. (16 marks)