0% found this document useful (0 votes)
1 views8 pages

Python Question b Ank

The document contains a comprehensive set of questions and answers related to Python programming, covering topics such as file handling, data types, functions, loops, and object-oriented programming principles. It includes 1-mark, 7-mark, and 10-mark questions for various units, providing a structured approach to learning Python. Each section is designed to test knowledge and understanding of Python concepts through practical examples and explanations.

Uploaded by

saranya
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)
1 views8 pages

Python Question b Ank

The document contains a comprehensive set of questions and answers related to Python programming, covering topics such as file handling, data types, functions, loops, and object-oriented programming principles. It includes 1-mark, 7-mark, and 10-mark questions for various units, providing a structured approach to learning Python. Each section is designed to test knowledge and understanding of Python concepts through practical examples and explanations.

Uploaded by

saranya
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/ 8

UNIT I :

1 Mark Questions

1. What is the file extension used for Python files?


.py
2. What symbol is used to write a single-line comment in Python?
#
3. What will be the output of print(2 + 3 * 4) in Python?
14 (because multiplication has higher precedence)
4. Which function is used to get input from the user in Python?
input()
5. Can variable names in Python start with a digit?
No
6. Are Python identifiers case-sensitive?
Yes
7. What keyword is used to define a function in Python?
def
8. Which keyword is used to define a class in Python?
class
9. Name one mutable data type in Python.
list
10. What does the len() function do?
Returns the length of a sequence
11. What is the output of "abc" + "123"?
abc123
12. Which operator is used for floor division in Python?
//
13. What is the result of the expression 10 > 5 and 3 < 2?
False
14. Name the operator used for exponentiation in Python.
**
15. What type of data does the expression 5 > 3 return?
Boolean (True)
16. What keyword is used for conditional branching in Python?
if
17. Is string a mutable or immutable data type in Python?
Immutable
18. Name any two Python keywords.
if, while (other acceptable answers: for, def, class, etc.)
19. Which built-in function is used to display output in Python?
print()
20. Variable names in Python are _______________ sensitive.

7 Marks Questions
1. Explain Python data types with examples.
2. Write a Python program that uses all basic arithmetic and logical operators. Explain the output.
3. What are Python identifiers and keywords? Explain the rules of naming identifiers with examples.
4. Explain Python string operations with examples.
5. Write a Python program that takes input from the user and performs basic operations on strings
and numbers.
6. Explain different types of Python operators with suitable examples.
10 Marks Questions
1. Explain the standard data types in Python with examples. Distinguish between mutable and
immutable types.
2. Describe different types of Python operators with examples. Also write a program to demonstrate
their usage.
3. What are variables in Python? Explain the rules for naming variables and the concept of dynamic
typing with examples.
4. Explain string operations and methods in Python with suitable examples.
UNIT II
1 Mark Questions

1. What is the syntax of a while loop in Python?


➤ while condition:
2. What type of loop is a while loop?
➤ Entry-controlled loop
3. Which keyword is used to start a while loop in Python?
➤ while
4. What happens if the condition in a while loop is always true?
➤ It leads to an infinite loop.
5. Which statement is used to terminate a while loop prematurely?
➤ break
6. Which statement skips the current iteration of a while loop?
➤ continue
7. How many times does a while loop execute if the condition is initially false?
➤ 0 times
8. What is the output of the following code?

i = 1
while i <= 3:
print(i)
i += 1
1
2
3

10. Which loop is preferred when the number of iterations is not known in advance?
➤ while loop
11. Which function is used to take input from the user in Python?
➤ input()
12. What is the default data type returned by input() in Python?
➤ str (string)
13. Which function is used to convert input into an integer?
➤ int()
14. Write the statement to take integer input from the user in Python.
➤ num = int(input("Enter a number: "))
15. How do you take multiple inputs in one line in Python?
➤ Using input().split()
16. What will be the output of:

x = input("Enter your name: ")


print(x)

➤ It will print whatever the user types.


7 MARK QUESTIONS

1. Write a Python program using a while loop to print numbers from 1 to 10.
2. Write a Python program to input numbers continuously and print their sum. Stop when
the user enters 0.
3. Write a program using a while loop to print the multiplication table of a number entered
by the user.
4. Write a Python program to input numbers and print only the positive numbers. Stop when
the user enters a negative number.
5. Write a program to calculate the sum of the first 10 natural numbers using a while loop.
6. Write a Python program that takes input from the user and checks if the number is even or
odd. Continue this until the user enters 0.
7. Write a Python program using a while loop to print the squares of numbers from 1 to 5.
8. Write a program to input a number and print whether it is positive or negative. Repeat
until the user enters 0.
9. Write a Python program to print all even numbers from 1 to 20 using a while loop.
10. Explain the use of the while loop in Python and write a simple example using input from
the keyboard.

10 MARK QUESTIONS

1. Write a Python program to input a number and display its multiplication table using a while
loop. Also explain the working of the loop.
2. Write a Python program to find the sum of all even numbers from 1 to 100 using a while loop.
Explain each step of your program.
3. Write a program that keeps asking the user to enter numbers. When the user enters -1, the
program should stop and display the total number of positive numbers entered. Also explain
the role of the loop condition.
4. What is a while loop in Python? Explain its syntax, flowchart, and working with the help of an
example that prints numbers from 10 to 1.
5. Write a program using while loop to count how many times a user enters a positive number.
The loop should stop if the user enters 0. Explain the logic used in your program.

UNIT III
1 MARK QUESTION

1. Q: What is a function in Python?


A: A function is a block of reusable code that performs a specific task.
2. Q: What keyword is used to define a function in Python?
A: def
3. Q: What is the default return value of a function that doesn’t have a return statement?
A: None
4. Q: Name any two built-in functions in Python.
A: print() and len()
5. Q: What does the len() function return?
A: The number of items in an object.
6. Q: Which function is used to take input from the user?
A: input()
7. Q: What is the use of type() function?
A: It returns the data type of the object
8. Q: What is function composition?
A: Calling one function inside another function.
9. Q: Can a function call another function in Python?
A: Yes
10. Q: What will be the output of print(len(str(123)))?
A: 3
11. Q: What is a parameter?
A: A variable defined in a function header.
12. Q: What is an argument?
A: A value passed to a function when calling it.
13. Q: What are default arguments?
A: Arguments that take default values if not provided.
14. Q: What is a keyword argument?
A: An argument passed by explicitly mentioning its parameter name.
15. Q: What is a function call?
A: Executing the code inside a function.
16. Q: How do you call a function named greet?
A: greet()
17. Q: What symbol is used to call a function?
A: Parentheses ()
18. Q: Can a function be called multiple times?
A: Yes
19. Q: What is the purpose of the return statement?
A: To send a result back from the function.
20. Q: Can a function return multiple values?
A: Yes
21. Q: What is the default return value of a function with no return statement?
A: None
22. Q: Which keyword is used to return a value from a function?
A: return
23. Q: What is recursion?
A: When a function calls itself.
24. Q: What is a recursive function?
A: A function that calls itself.
25. Q: What is the base case in recursion?
A: A condition to stop the recursive calls.
26. Q: Name a common example of a recursive problem.
A: Factorial calculation
27. Q: What is an anonymous function in Python?
A: A function without a name.
28. Q: Which keyword is used to create anonymous functions?
A: lambda
29. Q: What is another name for an anonymous function?
A: Lambda function
30. Q: Can a lambda function contain multiple expressions?
A: No

7 MARK QUESTIONS
1.Explain the concept of a function in Python. What are its advantages? Write a user-defined function to
calculate the square of a number and call it with an example
2. What are built-in functions in Python? List any five with examples and describe what they do.
3. What is function composition in Python? Write a Python program that uses one function inside another
to:
4.Differentiate between parameters and arguments with examples. Explain different types of arguments
supported in Python (positional, keyword, default, variable-length) with syntax and examples.
5. Explain how function calls and the return statement work in Python. Write a function that takes two
numbers as input and returns their sum and product. Also show how to use the returned values.
6. What is recursion? Write a recursive function in Python to calculate the factorial of a number. Explain
how recursion works with base and recursive cases.
7. What is a lambda (anonymous) function in Python? How is it different from a normal function? Write
examples of lambda functions used with map(), filter(), and reduce().
10 MARK QUESTIONS
1.Explain the concept of functions in Python. Describe the components of a function definition. Write a
complete program that defines and calls a user-defined function to check whether a number is even or
odd.

UNIT IV:
1 MARK QUESTION

1. Q1: What is a text file?


A: A file that contains data in readable text format.
2. Q2: Which file extension is commonly used for text files?
A: .txt
3. Q3: What is a directory?
A: A folder used to organize files.
4. Q4: What function is used to open a file in Python?
A: open()
5. Q5: Which mode is used to read a text file?
A: 'r'
6. Q6: Which mode is used to write to a text file (overwrite)?
A: 'w'
7. Q7: Which mode is used to append data to a file?
A: 'a'
8. Q8: What does os stand for in Python?
A: Operating System
9. Q9: Which module is used for directory operations in Python?
A: os
10. Q10: How to read all lines from a file at once?
A: Using .readlines()
11. Q11: Which function is used to remove a file in Python?
A: os.remove()
12. Q12: Which function is used to create a new directory in Python?
A: os.mkdir()
13. Q13: Which function lists all files and directories in a path?
A: os.listdir()
14. Q14: How to close a file in Python?
A: Using file.close()
15. Q15: What does with open() do?
A: It opens a file and ensures it is closed automatically.
16. Q16: What is the path of a file?
A: The location where the file is stored in the file system.
17. Q17: What is an absolute path?
A: The full path from the root directory to the file.
18. Q18: What is a relative path?
A: A path relative to the current working directory.
19. Q19: Which function changes the current working directory?
A: os.chdir()
20. Q20: Which function returns the current working directory?
A: os.getcwd()

7 MARK QUESTIONS
1. Explain how to perform file handling in Python.
2. What are the different modes in which a file can be opened in Python?
Explain each mode with suitable examples.
3. Write a Python program to count the number of: Lines,Words,Characters
in a given text file.
4. Explain the difference between text files and binary files.
Illustrate your answer with appropriate examples in Python.
5. Explain the use of with open() in file handling.Compare it with traditional file opening and
explain why it is preferred.

10 MARK QUESTIONS

1. 1. Explain in detail the steps involved in text file handling in Python.


Write a program that:
o Creates a file data.txt,
o Writes a list of employee names and salaries to it,
o Reads the data back,
o Displays only employees with salary above 50,000.

2.What is the difference between file handling and directory handling?


Write a Python program that:

 Creates a folder named records,


 Inside it, creates multiple text files with different names,
 Writes some data into each file,
 Lists all files in the directory

3. Explain exception handling in file operations.


Write a program that:

 Tries to read a file entered by the user,


 If the file does not exist, displays a proper error message,
 If it exists, displays the content.

Unit -5

1 MARK QUESTION

1. What does OOP stand for?


➤ Object-Oriented Programming
2. Name any two major principles of OOP.
➤ Encapsulation and Inheritance (also acceptable: Polymorphism, Abstraction)
3. What is the main advantage of using OOP?
➤ It promotes code reuse and modular design.
4. Which OOP principle promotes code reuse?
➤ Inheritance

5. What keyword is used to define a class in Python?


➤ class
6. What is the special method used to initialize a class?
➤ init()
7. Can a class contain both variables and methods? (Yes/No)
➤ YesCreating Objects

8. What is an object in OOP?


➤ An instance of a class
9. How do you create an object from a class in Python?
➤ By calling the class name, e.g., obj = ClassName()
10. True or False: You can create multiple objects from a single class.
➤ True

11. Can an object be passed as an argument to a function? (Yes/No)


➤ Yes
12. What type of variable in a class can be accessed using the object?
➤ Instance variable

13. Can a function return an object in Python? (Yes/No)


➤ Yes
14. What is returned by a method if there is no return statement?
➤ None

15. What does __dict__ attribute of a class return?


➤ A dictionary containing the class's namespace
16. Which built-in attribute gives the name of the class?
➤ name

17. What is inheritance in OOP?


➤ The process by which one class acquires the properties and behaviors of another class
18. What keyword is used to inherit a class in Python?
➤ class DerivedClass(BaseClass):

19. What is method overriding?


➤ Defining a method in a derived class with the same name as in the base class
20. Can a derived class override a method from its base class? (Yes/No)
➤ Yes

7 MARK QUESTIONS

1. Explain the four main principles of Object-Oriented Programming with suitable examples.
(Encapsulation, Abstraction, Inheritance, Polymorphism with code or real-world examples.)
2. Define a class in Python named Student with attributes name, roll_no, and marks. Include a
method to display the student details. Create two objects and display their data.
3. Differentiate between class variables and instance variables with examples.
4. Write a Python program where an object is passed as an argument to a function. Explain
how it works.
5. Demonstrate how a function can return an object in Python. Use a class Rectangle and a
method that returns an object with increased dimensions.
6. List and explain any five built-in class attributes in Python with examples.
7. What is inheritance? Explain single, multilevel, and multiple inheritance with Python code
snippets.
8. Explain method overriding with an example. How is it different from method overloading?
9. Write a Python program that demonstrates data encapsulation. How does it protect data
from direct access?
10. What is data hiding in Python? Show how private members of a class are declared and
accessed indirectly using methods.

10 MARK QUESTION

1. Explain the concepts of data encapsulation, data hiding, and method overriding in Object-
Oriented Programming. Illustrate each concept with suitable Python examples.
2. Write a Python program to demonstrate inheritance, including:

 A base class Person with attributes like name and age


 A derived class Employee with additional attributes like employee ID and salary
 Method overriding in the derived class
 Create and display objects of both classes

3.Discuss the concept of classes and objects in Python. Write a program that includes:

 A class BankAccount with attributes account_number, name, and balance


 Methods for deposit, withdraw, and display
 Create multiple objects and demonstrate transactions
 Explain how self works inside methods

4.What is the role of built-in class attributes in Python? Explain any five such attributes with
examples. Also show how they can be used to inspect and debug classes at runtime.

5.Explain the flow of object passing as an argument and returning an object from a function.
Write a Python program to demonstrate both features using a class Circle that calculates area and
returns a new modified circle object.

You might also like