0% found this document useful (0 votes)
97 views2 pages

Python Programming Exam Questions

This document contains questions for a Python programming exam covering various topics like data types, operators, functions, strings, lists, dictionaries, sets, modules, selection and iteration statements. The questions are divided into three sections - short answer questions in section I assessing basic concepts (2 marks each), paragraph questions in section II testing in-depth understanding (5 marks each), and essay questions in section III on advanced topics (10 marks each). Section I contains 15 questions evaluating understanding of Python's interpreted nature, statements, identifiers, datetime module, tuple method index(), if-elif-else, function categories, list definition, ceil() function, dictionary removal, single element tuple, set addition/removal, boolean expressions and multi

Uploaded by

tiwofic
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views2 pages

Python Programming Exam Questions

This document contains questions for a Python programming exam covering various topics like data types, operators, functions, strings, lists, dictionaries, sets, modules, selection and iteration statements. The questions are divided into three sections - short answer questions in section I assessing basic concepts (2 marks each), paragraph questions in section II testing in-depth understanding (5 marks each), and essay questions in section III on advanced topics (10 marks each). Section I contains 15 questions evaluating understanding of Python's interpreted nature, statements, identifiers, datetime module, tuple method index(), if-elif-else, function categories, list definition, ceil() function, dictionary removal, single element tuple, set addition/removal, boolean expressions and multi

Uploaded by

tiwofic
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

U 217303 Name: .......................................

(Pages: 2) Reg. No. ....................................

THIRD SEMESTER (CBCSS) DEGREE EXAMINATIONS,


NOVEMBER 2021
(Regular / Supplementary / Improvement)
Common Course – [Link]. Computer Science, [Link]. Electronics & B.C.A.
A11: Python Programming

Time: 2.5 Hours Max. Marks: 80

I. Answer the following questions in two or three sentences


(Each question carries 2 Marks): (Ceiling 25 Marks)
1. Why is python called an interpreted language?
2. What are statements in python? Give example.
3. What are python identifiers? Give example.
4. What is the purpose of datetime module in python?
5. Explain the purpose, syntax and usage of the built-in tuple method index( ). Ilustrate with
suitable examples.
6. Explain the simple if-elif-else statement in python.
7. What are the different general categories of functions in python?
8. How can you define and access lists in python? Ilustrate with examples.
9. Explain the purpose, syntax and usage of ceil( ) built-in function with an example.
10. How can you remove elements from dictionary? Ilustrate with suitable examples.
11. How can you create a tuple with single element in python? Ilustrate with example.
12. How can you add and remove elements in sets in python?
13. Explain how you can create complex boolean expressions using logical operators.
14. Explain how you can perform multi-way selection in python.
15. Explain the syntax, purpose and usage of the built-in string function capitalize( ) with
suitable examples.

II. Answer the following questions in a paragraph


(Each question carries 5 Marks): (Ceiling 35 Marks)
16. How python accepts user inputs? Explain with example.
17. List and explain various operators available in python.
18. What is meant by scope in python? What is meant by global scope? Illustrate its
significance with suitable example.
19. Describe the syntactic rules and usage of break and continue statements in python.
U 217303

20. Describe the purpose, syntax, usage of atleast five methods of the time module in python.
21. What is meant by scope in python? What is meant by local scope? Illustrate its
significance with suitable example.
22. What are the strings in python? How are strings defined and accessed in python?
23. What is meant by selection statements in python?

III. Write essays on any two of the following: (2 x 10 = 20 Marks)


24. Describe the syntactic rules and usage of while statement in python with example.
25. Describe python’s datatype.
26. What are dictionaries in python? How can you define and access dictionary elements?
Describe different methods of dictionaries in python.
27. Describe different types of arguments in python. Illustrate with examples.

Common questions

Powered by AI

The 'datetime' module in Python provides classes for manipulating dates and times, which are crucial for applications that involve date arithmetic or the representation of date and time. For example, the module can be used to calculate the difference between two dates, format dates in a specific way, or extract date components like day or month. An example is using datetime.datetime.now() to get the current date and time .

'Break' and 'continue' statements provide control over loop execution. 'Break' exits the nearest enclosing loop, terminating its further execution and immediately continuing with the next statement after the loop. Meanwhile, 'continue' skips the current iteration and proceeds with the next loop iteration. These statements facilitate managing loop control and avoiding unwanted iterations or early loop exits .

The 'index()' method in Python is used to find the first occurrence of a specified element within a tuple, returning the position of the element. Its syntax is tuple.index(element). For example, in the tuple ('a', 'b', 'c', 'a'), calling index('a') will return 0, the index of the first 'a' .

In Python, scope determines the accessibility of variables within the code. The local scope refers to variables defined within a function, accessible only within that function. For example, a variable inside a function is a local variable. Global scope involves variables defined outside any function, accessible throughout the module. For example, defining a variable at the module level makes it a global variable, usable by any function within the module. Correct usage of scopes prevents conflicts and helps manage the namespace effectively .

Python is called an interpreted language because its code is executed line by line by an interpreter, which converts the high-level language into a form understandable by the machine at runtime. Unlike compiled languages, which are translated entirely into machine code before execution, interpreted languages allow for more flexibility and ease of debugging .

The 'time' module provides various methods useful for time-related operations, such as time.time() for the current time in seconds since the epoch, time.sleep() to delay execution by a specified amount of seconds, time.strftime() to format time in a readable way, time.localtime() to convert the epoch time to the local time tuple, and time.gmtime() for converting to a UTC time tuple. These methods allow measuring, formatting, and coordinating time-sensitive processes .

Python lists are defined using square brackets and can store elements of different types, including integers, strings, and even other lists. For example, a list can be defined as my_list = [1, 'hello', [3.5, True]]. Elements can be accessed using indices, starting at 0. Basic operations include appending with append(), removing elements with remove(), and checking for elements with 'in' .

Python dictionaries are defined using curly braces, with key-value pairs, e.g., my_dict = {'a': 1, 'b': 2}. They allow access to values using keys, such as my_dict['a'] returning 1. Dictionaries can be manipulated with methods like .get() for safe access, .keys() and .values() for obtaining keys and values, and .popitem() for removing a key-value pair. These operations facilitate dynamic data storage and retrieval .

Complex boolean expressions in Python are constructed using logical operators - 'and', 'or', and 'not'. These operators are combined to form conditions that evaluate to True or False. For example, an expression like (x > 5 and x < 10) or (y == 3) combines conditions using 'and' and 'or'. It first checks if x is between 5 and 10 and evaluates to True if either part is true, demonstrating how multiple conditions can be assessed simultaneously .

Functions in Python are generally categorized into built-in functions, which are always available in the Python environment, and user-defined functions, created by programmers. Built-in functions such as len(), print(), and type() provide essential operations, while user-defined functions allow custom processing by defining specific functionality using 'def'. Each serves flexible or specific operations, including automation, modularization, and simplification of complex tasks .

You might also like