0% found this document useful (0 votes)
22 views1 page

Key Python Questions for Exams

The document outlines important questions and programming tasks related to Python, divided into two modules. Module 1 covers fundamental concepts such as functions, exception handling, and control flow statements, along with practical programming exercises. Module 2 focuses on lists and dictionaries, including their methods, differences, and related programming challenges.

Uploaded by

abdulrahman63562
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)
22 views1 page

Key Python Questions for Exams

The document outlines important questions and programming tasks related to Python, divided into two modules. Module 1 covers fundamental concepts such as functions, exception handling, and control flow statements, along with practical programming exercises. Module 2 focuses on lists and dictionaries, including their methods, differences, and related programming challenges.

Uploaded by

abdulrahman63562
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

Important Questions

Module 1
1)​ Demonstrate with example print(), input(), len(), format() and string concatenation and
replication
2)​ How to handle exceptions in python Explain with an example
3)​ Illustrate the use of break and continue with example
4)​ What are functions in python and how they are defined and used to modularize code?
5)​ Explain the local scope and global scope with local and global variables
6)​ Explain conditional branching statements with syntax. Write a suitable program for the same
7)​ What are user defined function? How can we pass the arguments to the functions? Explain
with suitable example
8)​ What are Comparison and Boolean operators? List all the Comparison and Boolean operators
9)​ List and explain with syntax and example the flow control statements in python

Programs
10)​Write a python program to check whether the number is even or odd
11)​Write a python program to print even numbers using step size in range()
12)​Write a python program to check whether the given number is positive, negative or zero
13)​Write a python program to generate Fibonacci sequence of length (N). Read N from console.
14)​Write a python program to check whether the given number is Armstrong or not
15)​Write a python program to guess the secret number between 1 to 25 within 5 guess if the
number is same then it is right guess else wrong guess
16)​Develop a python program to read the name and year of birth of a person. Display whether s
person is senior citizen or not

Module 2
1)​ Explain the list methods with example or (Explain any 4 built in method available for
working with lists)
2)​ Explain in and not in operators used in list with an example
3)​ Show that lists are mutable
4)​ Explain [Link] and [Link] functions with list
5)​ Differentiate between lists and dictionary
6)​ What are lists in python and how they are used to store and manipulate collection of data
7)​ Explain with example key(), values() and items() method
8)​ Explain the concept of list slicing and list traversing with example
9)​ How is tuple different from list?

Programs
10)​Write a python program to create a dictionary of 10 key value pairs and print only key on the
screen
11)​Write a program to count the frequency of characters using module PPrint
12)​Read N number from console and create a list. Develop a program to print the mean of the
numbers
13)​Write a program to add elements into dictionary using while loop
14)​What is dictionary? Write a python program to count occurrences of characters in a string and
print the count
15)​Write a python program that find the missing number from the given list n-1 ranging from 1
to n .There are no duplicates(Eg: 1246378 output:5)

Common questions

Powered by AI

Exception handling in Python is executed using 'try', 'except', 'finally', and 'else' blocks, allowing programs to handle errors gracefully without crashing. For example, 'try: block_to_attempt except ExceptionType: block_if_exception occurs' lets a programmer manage specific errors and maintain control flow. This enhances program stability and user experience by providing alternative solutions or appropriate exit mechanisms .

List methods in Python provide robust ways to manipulate list elements: 'append()' adds an element to the end, 'extend()' merges another list or iterable, 'insert(index, element)' places an element at a specified position, and 'pop()' removes and returns last or specified element, aiding dynamic data handling and management .

Tuples, though immutable, offer benefits like faster access times and safety in scenarios where data should not be altered, enhancing code integrity and performance. Their immutability also makes them hashable, suitable for use as keys in dictionaries where lists are unsuitable .

The 'random.choice' function selects a random item from a list, while 'random.shuffle' reorders the list randomly. These functions enable stochastic processes, crucial for simulations, random sampling, or testing algorithms' robustness under different conditions .

User-defined functions in Python, created using the 'def' keyword, allow programmers to encapsulate reusable blocks of code. They enhance modularity by breaking complex problems into smaller, manageable units. Example: 'def add(x, y): return x + y' defines an addition function, which can be reused multiple times, keeping code organized and preventing redundancy .

In Python, local scope refers to variables defined within a function, accessible only within that function. Global scope refers to variables defined outside any function, accessible globally. A function can read global variables, but modifying them requires the 'global' keyword. Mismanagement of scopes can lead to unexpected behavior or errors in function execution, especially when functions inadvertently alter global variables .

Comparison operators (like '==', '!=', '<', '>') compare values and yield Boolean results (True/False), crucial for decision-making processes. Boolean operators ('and', 'or', 'not') help in constructing complex logical expressions. They are essential for writing conditions in control statements and implementing logic, enabling code to respond dynamically to different scenarios .

String concatenation in Python, using the '+' operator or 'format' method, allows for dynamic creation of strings by merging multiple strings: 'str1 + str2'. Replication, using the '*' operator, can duplicate strings: 'str * n'. These methods streamline the creation and modification of text data, reducing redundancy and improving code readability .

Lists in Python are ordered, mutable sequences of elements accessible by indexes, suitable for collections where order matters. Dictionaries are unordered sets of key-value pairs, useful for fast access by unique keys, not indexable like lists. The choice largely depends on data organization needs and retrieval operations .

Flow control statements in Python include 'if', 'for', 'while', 'break', 'continue', and others that dictate the logical flow of a program. For example, 'if' statements allow conditional execution: 'if condition: execute_if_true'. The 'for' loop iterates over a sequence: 'for element in sequence: execute'. A 'while' loop continues as long as a condition is true: 'while condition: execute'. The 'break' statement exits the loop prematurely, while 'continue' skips to the next iteration. These control statements are crucial for implementing decision-making logic and repetitive tasks in programs .

You might also like