0% found this document useful (0 votes)
3 views

My Sample Apper Python

Uploaded by

javedgaur57
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

My Sample Apper Python

Uploaded by

javedgaur57
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Write a program for the given syntax and tabulate the results 1. str.isalpha() 2. str.

isdigit()

# Demonstrating str.isalpha() and str.isdigit()

examples = ["Hello", "1234", "Hello123", ""]

for example in examples:


print(f"'{example}'.isalpha(): {example.isalpha()}")
print(f"'{example}'.isdigit(): {example.isdigit()}")

2. Write a program for the given syntax and tabulate the results 1. isnumeric() 2. islower()

examples = ["123", "hello", "Hello123", ""]


for example in examples:
print(f"'{example}'.isnumeric(): {example.isnumeric()}")
print(f"'{example}'.islower(): {example.islower()}")

2. Explain in detail about Python Files, its types, functions and operations that can be performed on
files with examples. (16 marks)

3. Answer the following questions.

a) What are modules in Python? Explain. (4 marks)

b) Explain in details about namespaces and scoping. (8 marks)

c) Explain about the import statement in modules. (4 marks)

a) Write a program to enter a number in Python and print its octal and hexadecimal
equivalent. (6 marks)

d) Write an algorithm to check whether a student is pass or fail, the total marks of student
being the input. (4 marks)

4. Explain what is meant by namespaces and scoping?

Variables are names or identifiers that map to objects. A namespace is a dictionary of variable
names/keys and their corresponding object values. A python statement can access variables in a local
namespace and global namespace. If the local and global variables have the same name, the local
variable shadows the global variable. Each function has its own local namespace.

5. List some few common Exception types and explain when they occur.
 ArithmeticError- Base class for all errors that occur for numeric calculations.  OverflowError-
Raised when a calculation exceeds maximum limit for a numeric type.  ZeroDivisionError- Raised
when division or modulo by zero takes o place.  ImportError- Raised when an import statement fails.
 IndexError- Raised when an index is not found in a sequence.  RuntimeError- Raised when a
generated error does not fall into any category.

6. Explain pickling and how import pickle works.

Pickling is so called because it ―preserves‖ data structures. The pickle module contains the
necessary commands. To use it, import pickle and then open the file in the usual way: >>> import
pickle >>> f = open("test.pck","w")

6. What is the difference between break and continue statement?

The break statement is new. Executing it breaks out of the loop; the flow of execution moves to the
first statement after the loop. The continue statement ends the current iteration of the loop, but
continues looping. The flow of execution moves to the top of the loop, checks the condition, and
proceeds accordingly.

7. What is a text file? Give an example for a text file

A text file is a file that contains printable characters and whitespace, organized into lines separated
by newline characters. [Type text] To demonstrate, we‘ll create a text file with three lines of text
separated by newlines: >>> f = open("test.dat","w") >>> f.write("line one\nline two\nline three\n")
>>> f.close()

8. Which method is used to read the contents of a file which is already created?

The read method reads data from the file. With no arguments, it reads the entire contents of the
file: >>> text = f.read() >>> print text Now is the timeto close the file
9. Define python lists? With a program explain the concept of Accessing Values in Lists, updating lists
and deleting list elements.

10. With assumed list write a program for the given code Cmp(list1, list2), len(List), max(list) &
min(list) respectively.

11. Define python tuples? With program explain the concept of Accessing Values in tuples, updating
tuples and deleting tuple elements.

12. Mention & explain the python features in brief.

13. Explain the concepts of multiline statements, the quotation in python & comments in python in
brief.

14. Write short notes on python identifiers and keywords.

15. Mention the different types of operators, descriptions and suitable examples related to python
Assignment & bitwise operators.

16. Mention the different types of operators, descriptions and suitable examples related to python
Logical, Membership & Identity operators.

17. Explain the concept of Single Statement Suites and pass statement related to decision making &
loop control statements respectively.

18. With suitable program explain the concept of using else statement with loops related to for loop

19. With syntax & program explain the concept of elif statement in decision making
20. Explain the concept of break statement involved in loop control statements with flow diagram &
program.

21. Explain the concept of continue statement involved in loop control statements with flow diagram
& program.

22. Discuss the operator functions of String Special Operators & String Formatting Operator in detail.

23. Mention the function, description of random number functions and trigonometric functions
related to python numbers.

24. Explain the concept, syntax, program of capitalize() Method & center(width, fillchar) Method
related to Built-in String Methods.

26. Explain in brief about Built-in tuple Functions and Methods, Indexing, Slicing, and Matrixes &
Basic Tuples Operations.

27. With assumed list write a program for the given code Cmp(list1, list2), len(List), max(list) &
min(list) respectively

28. Explain in brief about Basic list Operations, Indexing, Slicing, and Matrixes & Built-in List
Functions and Methods.

29. Explain the concepts of No enclosing delimiters in brief and also write a program for Cmp(tuple1,
tuple2) syntax respectively

You might also like